I have a number of repetitive lines of code which I want to be able to generate dynamically, the result should look something like this:
PROC SURVEYSELECT DATA=IBIS3_4 (where = (Exkl_UtgUtl_Flyg=3)) METHOD=SRS SAMPSIZE=&Exkl_UtgUtl_Flyg_kvot SEED=1234567 OUT=Exkl_UtgUtl_Flyg;
RUN;
PROC SURVEYSELECT DATA=IBIS3_4 (where = (Exkl_UtgUtl_Tag=3)) METHOD=SRS SAMPSIZE=&Exkl_UtgUtl_Tag_kvot SEED=1234567 OUT=Exkl_UtgUtl_Tag;
RUN;
I can do generate the SAS-code quite easily in R. I just define a vector with the relevant strings:
strings<-c("Exkl_UtgUtl_Flyg",
"Exkl_UtgUtl_Tag",
"Exkl_UtgUtl_Farja",
"Exkl_UtgUtl_Taxi",
"Exkl_UtgUtl_Hyrbil",
"Exkl_UtgUtl_Driv",
"Exkl_UtgUtl_Bo",
"Exkl_UtgUtl_Resta",
"Exkl_UtgUtl_Shop",
"Exkl_UtgUtl_Aktiv",
"Exkl_UtgUtl_Annat",
"Exkl_UtgSwe_Flyg",
"Exkl_UtgSwe_Tag",
"Exkl_UtgSwe_Farja",
"Exkl_UtgSwe_Taxi",
"Exkl_UtgSwe_Hyrbil",
"Exkl_UtgSwe_Driv",
"Exkl_UtgSwe_Bo",
"Exkl_UtgSwe_Resta",
"Exkl_UtgSwe_Shop",
"Exkl_UtgSwe_Aktiv",
"Exkl_UtgSwe_Annat")
And then I define a for-loop:
for (i in strings){print(paste0("* ",i," *
PROC SURVEYSELECT DATA=IBIS3_4 (where = (",i,"=3)) METHOD=SRS
SAMPSIZE=&",i,"_kvot SEED=1234567
OUT=",i,";
RUN;"))}
I have to copy-paste the output into MS Word and remove all quotes/row numbers/rowbreak-signs, but at least I don't have to program 20+ identical lines of code manually.
But is there a way of doing this entirily in SAS? Can I put a do-loop inside a put-statement or something similar, in order to generate the code that I need?