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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1081 views
  • 1 like
  • 3 in conversation