Hi,
My basic question is to produce dataset based on 3 loops from our central repository. My desired output should be like this
Id1 | Id2 | Id3 | Id4 |
1 | 1 | 100 | I1 |
200 | I2 | ||
300 | I3 | ||
400 | I4 | ||
500 | I5 | ||
600 | I6 | ||
2 | 2 | 1100 | I7 |
1200 | I8 | ||
1300 | I9 | ||
1400 | I10 | ||
1500 | I11 | ||
1600 | I12 | ||
3 | 3 | 2100 | I13 |
2200 | I14 | ||
2300 | I15 | ||
2400 | I16 | ||
2500 | I17 | ||
2600 | I18 |
So I want to loop Id1 3 times thats my outermost loop, Id2 3 times thats my first inner loop and then Id3 and Id4 6 times each... I am able to produce output for Id1 but the only thing I M getting confused about is where to apply ends for inner loops and where to apply output statement... Guess my C background is making me confused... Any suggestions would be really helpful
Your example doesn't show ld2 looping but rather the same as ld1. And ld4 doesn't actually look like a loop per se.
When you say you want to create a dataset do you actuall want the values of ld1 and ld2 to be blank or did you suppress them to show the loop structure?
Assuming the blanks were for clarity but that the ld1 and ld2 variables are actually in the data this produces data as your example.
data junk (drop= count t);
count=0;
do ld1 = 1 to 3;
ld2 = ld1;
t= (ld2-1) * 1000;
do ld3 = (t+100) to (t+600) by 100;
count+1;
ld4= cats('l',put(count,f2.0));
output;
end;
end;
run;
What you said you wanted looks like this. Not sure that it is really much different than C or any other language.
do id1=1 to 3;
do id2=1 to 3;
do id3=1 to 6;
do id4=1 to 6;
output;
end;
end;
end;
end;
What you produced as a table looks more like this.
do id1=1 to 3;
id2=id1;
do id3loop=1 to 6;
id3=1000*(id1-1)+100*id3loop;
rec+1;
id4=cats('l',rec);
output;
end;
end;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.