DATA Step, Macro, Functions and more

Macro Variable time

Reply
Contributor
Posts: 45

Macro Variable time

[ Edited ]

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?

Contributor
Posts: 45

Re: Macro Variable time

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

Super User
Super User
Posts: 7,413

Re: Macro Variable time

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. 

Super Contributor
Posts: 408

Re: Macro Variable time

Haha mid-air collision with my almost identical response :-)
Super Contributor
Posts: 408

Re: Macro Variable time

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.

Ask a Question
Discussion stats
  • 4 replies
  • 117 views
  • 1 like
  • 3 in conversation