Hi,
I have three macro variables A, B
A is DATE9.
B is TIME8.
C is TIME8.
I have a table Z with several columns including:
D which is DATE9,
E which is TIME8.
F which is TIME8.
I want to fill in F whith C only for rows where A=D and B=E
I do this:
data Z; set Z; if F = . AND D = "&A."d AND E = "&B."t then do; F = "&C."t; end; run;
Quite easy but doesn't work...
It seems the problem comes from:
AND E = "&B."t
Because When I do this:
data Z; set Z; if F = . AND D = "&A."d /*AND E = "&B."t*/ then do; F = "&C."t; end; run;
...it works!
My macro variables B is correct because when I do this:
data Z; set Z; if F = . AND D = "&A."d /*AND E = "&B."t*/ then do; F = "&B."t; end; run;
it works too!
Do you know why?
I edited my message. The good version is the one I just posted
What "doesn't work"? Post an example showing the %let's and some simple test data which illustrate your points. Also check by putting on:
options mlogic mprint sybolgen;
To see exactly what is happening.
Also note that macro variables are not a good storage medium for data. You would find your programming simpler if you put your data into a dataset, then merge that information onto your other data. This will make coding simpler and you can use actual date/time variables.
Your code seems fine. The issue is likely in the values of the macro variables.
A good way to start troubleshooting macro issues is to set the proper options:
Execute
options mprint symbolgen mlogic;
and rerun your code. Observe the log and see where that gets you. And please add the log of your code and some sample of your data. You say it doesn't work but it is inclear in which way it doesn't. Help us help you.
Regards,
- Jan.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.