Hi,
I am trying to figure out why a macro variable is not resolving correctly when I use call symput.
Here is how I define the macro variable:
data cross2;
set cross crossb2;
if &domain. = 1 and missing(&by.) and F_&by. = "Total" and F_&var. = "Total" then do;
&by.=99;
scale=WgtFreq/Frequency;
call symput("scale",scale);
end;
run;
Here is how I want to use the macro variable:
data cross3(keep=&by. VarLabel NMISS Scale Mean stderr min max);
set cross2;
if &domain. = 1 then output;
scale=&scale.;
WgtNMISS = &scale.*NMISS;
run;
%put &=scale;
When I run the above code, I am getting a missing value for scale in a data set print out, but the log print out of the variable shows it resolved to a number.
Any idea why the number isn't printing in the data set?
When you use an explicit output such as :
data cross3(keep=&by. VarLabel NMISS Scale Mean stderr min max);
set cross2;
if &domain. = 1 then output;
scale=&scale.;
WgtNMISS = &scale.*NMISS;
run;
Then unless there is another output statement nothing calculated or manipulated after the first output will be in the output data set because you did not tell SAS you wanted it output. The variables will be there with missing values.
If you only want to process data where &domain variable =1 then use
Where &domain=1;
or
If &domain=1;
When you use an explicit output such as :
data cross3(keep=&by. VarLabel NMISS Scale Mean stderr min max);
set cross2;
if &domain. = 1 then output;
scale=&scale.;
WgtNMISS = &scale.*NMISS;
run;
Then unless there is another output statement nothing calculated or manipulated after the first output will be in the output data set because you did not tell SAS you wanted it output. The variables will be there with missing values.
If you only want to process data where &domain variable =1 then use
Where &domain=1;
or
If &domain=1;
ballardw, you nailed it!
This was my issue all along. I am working with someone else's code and didn't realize that they had put the output statement in there. Not sure why they did, it is completely unnecessary.
Thank you!
I don't understand why there are two steps at all. Can you show what's inside of the datasets cross and crossb2?
It seems as you are trying to replace/calculate scale/WgtMiss using the values found in a total-obeservation. There are easier ways to do this, eg. merging the total-observation with detail obs. But to provide code, i need to have data to work with.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.