Syntax If on Occurrences Variable

Discussions about CSEntry
langitluna
Posts: 32
Joined: December 4th, 2016, 10:57 pm

Syntax If on Occurrences Variable

Post by langitluna »

Hi Expert

Help me please.
I have two records that both Occurrences variables type.
1. FQ1 with 100 Occurrences : FQ1(1), FQ1(2),FQ1(3) ... FQ1(100)
2. Q1 with 150 Occurrences : Q1(1), Q1(2), Q1(3) ... Q1(150)

What is the short syntax to convert any entry on FQ() to be binary 1 or 0 on Q1() ?

something like this, but this is will getting long syntax, and does not work as well.

Code: Select all

if FQ()=1 then Q1(1)=1 else Q1(1)=0;
if FQ()=2 then Q1(2)=1 else Q1(2)=0;
if FQ()=3 then Q1(1)=1 else Q1(3)=0;
I am attaching the program I want to do like this.
Attachments
QQ2016.zip
(2.32 KiB) Downloaded 298 times
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Syntax If on Occurrences Variable

Post by josh »

If you are in the proc for FQ1 then you use curocc() to get the current occurrence number:
PROC FQ1

if FQ1 = curocc() then
    Q1(
curocc()) = 1
else
    Q1(
curocc()) = 0;
endif;
On the first occurrence curocc() will be 1, then on the next occurrence 2,... This way you do not need to repeat the logic 100 times.

Alternatively if you do this outside the proc of FQ1 you (for example in the group post proc) you could use a loop:
PROC FQ1000

do numeric i = 1 while i <= totocc(FQ1000)
    
if FQ1(i) = i then
        Q1(i) =
1;
    
else
        Q1(i) =
0;
    
endif;
enddo;
langitluna
Posts: 32
Joined: December 4th, 2016, 10:57 pm

Re: Syntax If on Occurrences Variable

Post by langitluna »

Hi Josh

Thank you for your quick respond.
The syntax you give I had tested. Its worked if FQ1 and Q1 entry on in order, right ?

I want: the values will entry on FQ1000 Rooster does not in order.
For example I want to entry on FQ1000 rooster: 1,2,3,5,10,12,7 Then on Q1 will convert to binary value 1 or 0.

Please Josh if any curocc() syntax to deal with this ? Thank you in advance.
Attachments
curocc1.PNG
curocc1.PNG (66.7 KiB) Viewed 7574 times
khurshid.arshad
Posts: 572
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: Syntax If on Occurrences Variable

Post by khurshid.arshad »

Dear langitluna

Can you explain that why occurrence 4 =0 and occurrence 5=1.

thanks.
a.
langitluna
Posts: 32
Joined: December 4th, 2016, 10:57 pm

Re: Syntax If on Occurrences Variable

Post by langitluna »

Hi khurshid.arshad

Thanks for respond.

4= 0 because: there is no entry 4 on FQ1 field (FQ1000 rooster)
5= 1 because: there is 5 that entry on FQ1 field (Q1000 rooster)

So the variables on Q1000 Rooster are converted to 1 or 0 on what entry on FQ11000.
Please see QQ2016.zip program above.

I tried with this syntax below but it does not work:

Code: Select all

if FQ1 = 1 then Q1(1) = 1 else Q1(1) = 0;endif;
if FQ1 = 2 then Q1(2) = 1 else Q1(2) = 0;endif;
if FQ1 = 3 then Q1(3) = 1 else Q1(3) = 0;endif;
if FQ1 = 4 then Q1(4) = 1 else Q1(4) = 0;endif;
if FQ1 = 5 then Q1(5) = 1 else Q1(5) = 0;endif;
if FQ1 = 6 then Q1(6) = 1 else Q1(6) = 0;endif;
and so on son on
khurshid.arshad
Posts: 572
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: Syntax If on Occurrences Variable

Post by khurshid.arshad »

It means that if you are going to enter 4 on 8th occurrence in (FQ1000 rooster) then 4th occurrence answer automatically convert from 0 to 1 in (Q1000 rooster).

You have already mentioned that your entry is not in sequence.
a.
langitluna
Posts: 32
Joined: December 4th, 2016, 10:57 pm

Re: Syntax If on Occurrences Variable

Post by langitluna »

Hi khurshid.arshad and Josh

Yes.
Finally I have solve it out. But still, if you have any other way, I mean shortest syntax.
Please see my attached programe QQ2016_2.zip.

and here the complete syntax

Code: Select all

{Application 'QQ' logic file generated by CSPro}
PROC GLOBAL

PROC QQ_FF

PROC FQ1

if FQ1 = 0 then skip to Q2;endif;
 
if FQ1 = 1 then Q1(1) = 1; endif;
if FQ1 = 2 then Q1(2) = 1; endif;
if FQ1 = 3 then Q1(3) = 1; endif;
if FQ1 = 4 then Q1(4) = 1; endif;
if FQ1 = 5 then Q1(5) = 1; endif;
if FQ1 = 6 then Q1(6) = 1; endif;
if FQ1 = 7 then Q1(7) = 1; endif;
if FQ1 = 8 then Q1(8) = 1; endif;
if FQ1 = 9 then Q1(9) = 1; endif;
if FQ1 = 10 then Q1(10) = 1; endif;
if FQ1 = 11 then Q1(11) = 1; endif;
if FQ1 = 12 then Q1(12) = 1; endif;
if FQ1 = 13 then Q1(13) = 1; endif;
if FQ1 = 14 then Q1(14) = 1; endif;
if FQ1 = 15 then Q1(15) = 1; endif;
if FQ1 = 16 then Q1(16) = 1; endif;
if FQ1 = 17 then Q1(17) = 1; endif;
if FQ1 = 18 then Q1(18) = 1; endif;
if FQ1 = 19 then Q1(19) = 1; endif;
if FQ1 = 20 then Q1(20) = 1; endif;
if FQ1 = 21 then Q1(21) = 1; endif;
if FQ1 = 22 then Q1(22) = 1; endif;
if FQ1 = 23 then Q1(23) = 1; endif;
if FQ1 = 24 then Q1(24) = 1; endif;
if FQ1 = 25 then Q1(25) = 1; endif;
if FQ1 = 26 then Q1(26) = 1; endif;
if FQ1 = 27 then Q1(27) = 1; endif;
if FQ1 = 28 then Q1(28) = 1; endif;
if FQ1 = 29 then Q1(29) = 1; endif;
if FQ1 = 30 then Q1(30) = 1; endif;
if FQ1 = 31 then Q1(31) = 1; endif;
if FQ1 = 32 then Q1(32) = 1; endif;
if FQ1 = 33 then Q1(33) = 1; endif;
if FQ1 = 34 then Q1(34) = 1; endif;
if FQ1 = 35 then Q1(35) = 1; endif;
if FQ1 = 36 then Q1(36) = 1; endif;
if FQ1 = 37 then Q1(37) = 1; endif;
if FQ1 = 38 then Q1(38) = 1; endif;
if FQ1 = 39 then Q1(39) = 1; endif;
if FQ1 = 40 then Q1(40) = 1; endif;
if FQ1 = 41 then Q1(41) = 1; endif;
if FQ1 = 42 then Q1(42) = 1; endif;
if FQ1 = 43 then Q1(43) = 1; endif;
if FQ1 = 44 then Q1(44) = 1; endif;
if FQ1 = 45 then Q1(45) = 1; endif;
if FQ1 = 46 then Q1(46) = 1; endif;
if FQ1 = 47 then Q1(47) = 1; endif;
if FQ1 = 48 then Q1(48) = 1; endif;
if FQ1 = 49 then Q1(49) = 1; endif;
if FQ1 = 50 then Q1(50) = 1; endif;
if FQ1 = 51 then Q1(51) = 1; endif;
if FQ1 = 52 then Q1(52) = 1; endif;
if FQ1 = 53 then Q1(53) = 1; endif;
if FQ1 = 54 then Q1(54) = 1; endif;
if FQ1 = 55 then Q1(55) = 1; endif;
if FQ1 = 56 then Q1(56) = 1; endif;
if FQ1 = 57 then Q1(57) = 1; endif;
if FQ1 = 58 then Q1(58) = 1; endif;
if FQ1 = 59 then Q1(59) = 1; endif;
if FQ1 = 60 then Q1(60) = 1; endif;
if FQ1 = 61 then Q1(61) = 1; endif;
if FQ1 = 62 then Q1(62) = 1; endif;
if FQ1 = 63 then Q1(63) = 1; endif;
if FQ1 = 64 then Q1(64) = 1; endif;
if FQ1 = 65 then Q1(65) = 1; endif;
if FQ1 = 66 then Q1(66) = 1; endif;
if FQ1 = 67 then Q1(67) = 1; endif;
if FQ1 = 68 then Q1(68) = 1; endif;
if FQ1 = 69 then Q1(69) = 1; endif;
if FQ1 = 70 then Q1(70) = 1; endif;
if FQ1 = 71 then Q1(71) = 1; endif;
if FQ1 = 72 then Q1(72) = 1; endif;
if FQ1 = 73 then Q1(73) = 1; endif;
if FQ1 = 74 then Q1(74) = 1; endif;
if FQ1 = 75 then Q1(75) = 1; endif;
if FQ1 = 76 then Q1(76) = 1; endif;
if FQ1 = 77 then Q1(77) = 1; endif;
if FQ1 = 78 then Q1(78) = 1; endif;
if FQ1 = 79 then Q1(79) = 1; endif;
if FQ1 = 80 then Q1(80) = 1; endif;
if FQ1 = 81 then Q1(81) = 1; endif;
if FQ1 = 82 then Q1(82) = 1; endif;
if FQ1 = 83 then Q1(83) = 1; endif;
if FQ1 = 84 then Q1(84) = 1; endif;
if FQ1 = 85 then Q1(85) = 1; endif;
if FQ1 = 86 then Q1(86) = 1; endif;
if FQ1 = 87 then Q1(87) = 1; endif;
if FQ1 = 88 then Q1(88) = 1; endif;
if FQ1 = 89 then Q1(89) = 1; endif;
if FQ1 = 90 then Q1(90) = 1; endif;
if FQ1 = 91 then Q1(91) = 1; endif;
if FQ1 = 92 then Q1(92) = 1; endif;
if FQ1 = 93 then Q1(93) = 1; endif;
if FQ1 = 94 then Q1(94) = 1; endif;
if FQ1 = 95 then Q1(95) = 1; endif;
if FQ1 = 96 then Q1(96) = 1; endif;
if FQ1 = 97 then Q1(97) = 1; endif;
if FQ1 = 98 then Q1(98) = 1; endif;
if FQ1 = 99 then Q1(99) = 1; endif;
if FQ1 = 100 then Q1(100) = 1; endif;
if FQ1 = 101 then Q1(101) = 1; endif;
if FQ1 = 102 then Q1(102) = 1; endif;
if FQ1 = 103 then Q1(103) = 1; endif;
if FQ1 = 104 then Q1(104) = 1; endif;
if FQ1 = 105 then Q1(105) = 1; endif;
if FQ1 = 106 then Q1(106) = 1; endif;
if FQ1 = 107 then Q1(107) = 1; endif;
if FQ1 = 108 then Q1(108) = 1; endif;
if FQ1 = 109 then Q1(109) = 1; endif;
if FQ1 = 110 then Q1(110) = 1; endif;
if FQ1 = 111 then Q1(111) = 1; endif;
if FQ1 = 112 then Q1(112) = 1; endif;
if FQ1 = 113 then Q1(113) = 1; endif;
if FQ1 = 114 then Q1(114) = 1; endif;
if FQ1 = 115 then Q1(115) = 1; endif;
if FQ1 = 116 then Q1(116) = 1; endif;
if FQ1 = 117 then Q1(117) = 1; endif;
if FQ1 = 118 then Q1(118) = 1; endif;
if FQ1 = 119 then Q1(119) = 1; endif;
if FQ1 = 120 then Q1(120) = 1; endif;
if FQ1 = 121 then Q1(121) = 1; endif;
if FQ1 = 122 then Q1(122) = 1; endif;
if FQ1 = 123 then Q1(123) = 1; endif;
if FQ1 = 124 then Q1(124) = 1; endif;
if FQ1 = 125 then Q1(125) = 1; endif;
if FQ1 = 126 then Q1(126) = 1; endif;
if FQ1 = 127 then Q1(127) = 1; endif;
if FQ1 = 128 then Q1(128) = 1; endif;
if FQ1 = 129 then Q1(129) = 1; endif;
if FQ1 = 130 then Q1(130) = 1; endif;
if FQ1 = 131 then Q1(131) = 1; endif;
if FQ1 = 132 then Q1(132) = 1; endif;
if FQ1 = 133 then Q1(133) = 1; endif;
if FQ1 = 134 then Q1(134) = 1; endif;
if FQ1 = 135 then Q1(135) = 1; endif;
if FQ1 = 136 then Q1(136) = 1; endif;
if FQ1 = 137 then Q1(137) = 1; endif;
if FQ1 = 138 then Q1(138) = 1; endif;
if FQ1 = 139 then Q1(139) = 1; endif;
if FQ1 = 140 then Q1(140) = 1; endif;
if FQ1 = 141 then Q1(141) = 1; endif;
if FQ1 = 142 then Q1(142) = 1; endif;
if FQ1 = 143 then Q1(143) = 1; endif;
if FQ1 = 144 then Q1(144) = 1; endif;
if FQ1 = 145 then Q1(145) = 1; endif;
if FQ1 = 146 then Q1(146) = 1; endif;
Attachments
QQ2016_2.zip
(3.37 KiB) Downloaded 284 times
khurshid.arshad
Posts: 572
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: Syntax If on Occurrences Variable

Post by khurshid.arshad »

Dear langitluna

After a small change in josh syntax.

Code: Select all

PROC FQ1
numeric i, linenumber;

if FQ1 = 0 then skip to Q2;endif;

linenumber=FQ1;
do  i = 1 while i <= 100
    if FQ1(i) = linenumber then
        Q1(linenumber) = 1;
    else
    endif;
enddo;

I hope it works for you.

a.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Syntax If on Occurrences Variable

Post by josh »

If they can be entered out of order then I would probably use a loop but also pre-fill Q1 with zeros to handle the possible gaps. Something like this:
PROC FQ1000

// Set everything in Q1 to zero
do numeric i = 1 while i <= maxocc(Q1000)
   Q1(i) =
0;
enddo;

// Set ones in Q1 where there are corresponding entries in FQ1
do numeric i = 1 while i <= totocc(FQ1000)
    
if FQ1(i) in 1:maxocc(Q1000) then
        Q1(FQ1(i)) =
1;
    
endif;
enddo;
I think Khurshids solution will work too since you are in operator controlled mode but if you were in system controlled mode you would not want to use skip in this situation as the values in Q1 would not get saved.
langitluna
Posts: 32
Joined: December 4th, 2016, 10:57 pm

Re: Syntax If on Occurrences Variable

Post by langitluna »

Dear Josh

Thanks.

How the syntax for:
1. prevent blank on first raw of FQ1 that is FQ1(1). Like:
If FQ(1) = NotAppl then Errmsg("Please entry at least one"); endif;
2. Then for the next raw if it blank then skip to next variable or FQ2. Like:
If FQ1(2 above) then skip to FQ2.

Please help.

Out of topic:
Seems some of thread dissapeared doesn't it? For about two weeks I could not get through this forum. Some error messege SQL server something... I dont know weather this happened on my machine only.
Post Reply