hello,
I have a file for footnotes, like below:
data fnt; length fnt_1 $80 fnt_2 $80 fnt_3 $80 fnt_4 $80; infile datalines dlm=',' ; input fnt_1 fnt_2 fnt_3 fnt_4 ; datalines; "Teach us the most important lessons in life", "Give the best advice and know the right thing to say." ,"Given us two of the best things we could ever have: life and love.", "Loved us unconditionally" ; run;
I would like to use do loop to write my footnotes. I had my codes as:
data _null_; set fnt; do i=1 to 4.; call execute( cat( "footnote" , i , " j = l " , fnt_i , " ;" ) ) ; end ; run;
However I got errors as below. 1-4 were added to footnote, but I could not get the value of fnt_1 to fnt_4 out.
Could anyone guide me on this? Ideal outcome is I can generate the line as:
footnote1 j=l "Teach us the most important lessons in life"; footnote2 j=l "Give the best advice and know the right thing to say.";
Thanks.
you could do it like this:
data _null_;
set fnt;
do fnt = fnt_1, fnt_2, fnt_3, fnt_4;
i+1;
call execute( cat( cats("footnote",i), " j = l ", fnt, " ;")) ;
end ;
run;
but I wouldn't call it "good programming practice"
Array in SAS, in it's fundamental version, is just a way to loop over multiple variables conveniently.
Bart
data _null_;
set fnt;
array fnt[*] fnt_:;
do i=1 to 4;
call execute( cat( cats("footnote",i), " j = l ", fnt[i], " ;")) ;
end ;
run;
thanks so much!
I am new to sas. Please pardon me if my question is too silly : Do we have to do array? Is it possible to directly use value from fnt.fnt_1 to fnt_4?
Sure.
If you want FNT_1 then just type that string into you program instead. Get it to work to generate one footnote from one variable. Then replicate the line and change the 1's to 2's. Repeat. That is called WALLPAPER code since it has a repeating pattern like a wallpaper pattern.
But the ARRAY statement allows you to reference variables by an index so that it is possible to loop over the index.
you could do it like this:
data _null_;
set fnt;
do fnt = fnt_1, fnt_2, fnt_3, fnt_4;
i+1;
call execute( cat( cats("footnote",i), " j = l ", fnt, " ;")) ;
end ;
run;
but I wouldn't call it "good programming practice"
Array in SAS, in it's fundamental version, is just a way to loop over multiple variables conveniently.
Bart
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.