BookmarkSubscribeRSS Feed
Planck
Obsidian | Level 7

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?

4 REPLIES 4
Planck
Obsidian | Level 7

I edited my message. The good version is the one I just posted

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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. 

jklaverstijn
Rhodochrosite | Level 12
Haha mid-air collision with my almost identical response 🙂
jklaverstijn
Rhodochrosite | Level 12

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.

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
  • 4 replies
  • 1834 views
  • 1 like
  • 3 in conversation