I'm importing several Excel files. Each has 3 sheets: Known from Source 1 (known1), Known from Source 2 (known2), and Estimated (est). After importation, all 3 sheets will be merged into a single SAS file. I need to flag the imported records to show if they came from the Estimated sheet or not.
I think I need a conditional IF statement, but I can't get the code right. The code I have now basically says that if the variable est equals the value "est" then... But of course there is no variable named est, so it doesn't work.
%macro import(sheet);
DATA want; SET have;
IF &sheet. = "est" THEN flg_est = 1; ELSE flg_est= 0;
RUN;
%mend;
%import(known1)
%import(known2)
%import(est)
To see why you got that message turn the MPRINT option before running the macro.
You should see that you generated lines like:
IF est = "est" THEN flg_est = 1;
Which to the data step compiler means you want to compare the value of the variable named EST to the string literal "est".
Just add quotes around the value in your macro code:
IF "&sheet." = "est" THEN flg_est = 1;
So that it generates this SAS code:
IF "est" = "est" THEN flg_est = 1
To see why you got that message turn the MPRINT option before running the macro.
You should see that you generated lines like:
IF est = "est" THEN flg_est = 1;
Which to the data step compiler means you want to compare the value of the variable named EST to the string literal "est".
Just add quotes around the value in your macro code:
IF "&sheet." = "est" THEN flg_est = 1;
So that it generates this SAS code:
IF "est" = "est" THEN flg_est = 1
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.