BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Wolverine
Pyrite | Level 9

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)

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

View solution in original post

1 REPLY 1
Tom
Super User Tom
Super User

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 311 views
  • 1 like
  • 2 in conversation