BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Alchemy1ndex
Fluorite | Level 6

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?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;

View solution in original post

4 REPLIES 4
ballardw
Super User

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;

Alchemy1ndex
Fluorite | Level 6

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!

Cynthia_sas
SAS Super FREQ
Hi:
I don't understand what you mean by "the number isn't printing in the data set" -- do you want to see the values in the resolved code? Have you turned on the MPRINT and SYMBOLGEN options?

Without data, no one can test your code.

Cynthia
andreas_lds
Jade | Level 19

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 4 replies
  • 716 views
  • 1 like
  • 4 in conversation