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

SAS Version 9.4

 

The following source code....

proc sort data= work.Primary_group4; by constituent_name ; run;

data work.Eqn1415_Warning0;
	set work.Primary_group4 end=eof;
	by constituent_name;
	retain flagit 0;
	retain warning0;
	if first.constituent_name then PrimaryResultsCount=0;
	PrimaryResultsCount+1;
	if last.constituent_name then do;
		if PrimaryResultsCount<6 or conversionfactor= . then do;
				WARNING0=constituent_name;
				flagit+1;
				end;
		output;
		end;
	if flagit ne 0 then call symputx("Eqn1415_flag0","(0)"); 
			else call symputx("Eqn1415_flag0"," ");
	if warning0="Curium-242" then call symputx("Curium242_flag0","(0)Cobalt60 ");
			else call symputx("Curium242_flag0"," ");
	if warning0="Cobalt-60" then call symputx("Cobalt60_flag0","(0)Cobalt60 ");
			else call symputx("Cobalt60_flag0"," ");
	if warning0="Europium-154" then call symputx("Europium154_flag0","(0)Europium154");
			else call symputx("Europium154_flag0"," ");
	if warning0="Plutonium-239/240" then call symputx("Plutonium239_flag0","(0)Plutonium-239 ");
			else call symputx("Plutonium239_flag0"," ");
	if warning0="Technetium-99" then call symputx("Technetium99_flag0","(0)Technetium99");
			else call symputx("Technetium99_flag0"," ");
	drop reported_value  Reported_Units Qualifiers Converted_flag  Result_Type flagit;
run;

%put &Eqn1415_flag0;
%put &Cobalt60_flag0;
%put &Plutonium239_flag0;
%put &Technetium99_flag0;
%put &Curium242_flag0;

Creates the dataset work.Eqn1415_warning0....

7.JPGddd

The log is showing the calls to symputx failed for Plutonium-239/240, Curium242_flag0, but worked for Technetium99_flag0

 

2397  %put &Eqn1415_flag0;
(0)
2398  %put &Cobalt60_flag0;

2399  %put &Plutonium239_flag0;

2400  %put &Technetium99_flag0;
(0)Technetium99
2401  %put &Curium242_flag0;

 

 

Totally confused as how to fix it so that the flags work whenever warning0 is given a constituent name.

 

Thanks for the help.

 

Jane

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
Jane,

It's easy to set up flags, as many as are helpful. But macro variables are the wrong tool for the job. Just set up DATA step variables instead. That would let you save separate flags for each person, and report the results pretty easily. Macro variables don't support either of those objectives.

View solution in original post

9 REPLIES 9
Astounding
PROC Star
The IF THEN ELSE logic that uses CALL SYMPUTX gets applied on every observation. So the macro variables get replaced every time. The final values depend on the final observation only.

What is the result that you would like to see?
jawhitmire
Quartz | Level 8

Thank you for the quick reply.

 

I would like to flag each constituent with a warning.  

That is, create a macro variable that is blank when there is no warning, but prints the name of the constituent when conversionfactor is . or when PrimaryResultsCount<6.  

The macro will later be referenced in an executive summary.

 

Thanks again,

Jane

ballardw
Super User

@jawhitmire wrote:

Thank you for the quick reply.

 

I would like to flag each constituent with a warning.  

That is, create a macro variable that is blank when there is no warning, but prints the name of the constituent when conversionfactor is . or when PrimaryResultsCount<6.  

The macro will later be referenced in an executive summary.

 

Thanks again,

Jane


How are you creating the executive summary? If it is to create a list of those with a flag set then consider:

 

data want;
   set sashelp.class;
   if sex='F' then weightflag= weight>90;
   else if sex='M' then weightflag= weight>110;
run;

Proc print data=want noobs;
   where weightflag;
   title "Names of children with Weight Flag set";
   var name;
run;title;

The rules for weightflag were very arbitrary just to create the flag variable as a dichotomous 1/0 coded value.

Select the values to display with a where clause for example and Var to show the values you need for your summary.

 

Better might be to provide some example data in the form of data step code and how you want the executive summary to appear.

There are LOTS of things that can be done with properly structured data and report procedures. Stuffing lots of values into macro variables is quite often the most difficult to get nice output from.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

jawhitmire
Quartz | Level 8
data work.Eqn1415_Warning0;
	set work.Primary_group4 end=eof;
	by constituent_name;
	retain flagit 0;
	retain warning0;
	if first.constituent_name then PrimaryResultsCount=0;
	PrimaryResultsCount+1;
	if last.constituent_name then do;
		if PrimaryResultsCount<6 or conversionfactor= . then do;
				WARNING0=constituent_name;
			if warning0="Cobalt-60" then call symputx("Cobalt60_flag0","(0)Cobalt60 ");
			else call symputx("Cobalt60_flag0"," ");
			if warning0="Europium-154" then call symputx("Europium154_flag0","(0)Europium154");
			else call symputx("Europium154_flag0"," ");
			if warning0="Plutonium-239/240" then call symputx("Plutonium239_flag0","(0)Plutonium-239 ");
			else call symputx("Plutonium239_flag0"," ");
			if constituent_name="Curium-242" then call symputx("Curium242_flag0","(0)Cobalt60 ");
			else call symputx("Curium242_flag0"," ");
			if warning0="Technetium-99" then call symputx("Technetium99_flag0","(0)Technetium99");
			else call symputx("Technetium99_flag0"," ");
				flagit+1;
				end;
		output;
		end;
	if flagit ne 0 then call symputx("Eqn1415_flag0","(0)"); 
			else call symputx("Eqn1415_flag0"," ");
	drop reported_value  Reported_Units Qualifiers Converted_flag  Result_Type flagit;
run;

%put &Eqn1415_flag0;
%put &Cobalt60_flag0;
%put &Plutonium239_flag0;
%put &Technetium99_flag0;
%put &Curium242_flag0;

This produces the same results but only uses symputx when the last constituent_name.

Tom
Super User Tom
Super User

How are you naming the macro variables?  They need to have valid SAS names. So a value like Plutonium-239/240 is not value because of the hyphen and slash.

jawhitmire
Quartz | Level 8

Thank you for the reply.

The dataset is very large with constituent_name as shown "239/240" .

I must work with it as given, but was careful of the formatting for the macro name.

Is there a way to ignore the "/" from the imported Excel spreadsheet?

Thanks again,

Jane

Tom
Super User Tom
Super User

@jawhitmire wrote:

Thank you for the reply.

The dataset is very large with constituent_name as shown "239/240" .

I must work with it as given, but was careful of the formatting for the macro name.

Is there a way to ignore the "/" from the imported Excel spreadsheet?

Thanks again,

Jane


It is not clear at all what you intend to do with these macro variables, but such a case it would probably be best to just assign a number to each (whatever you unit is here) and use the number in generating the macro variable name.

Tom
Super User Tom
Super User

Why are you testing FLAGIT when that variable will increment across groups?

Did you forget to reset it to zero when starting a new group?

Astounding
PROC Star
Jane,

It's easy to set up flags, as many as are helpful. But macro variables are the wrong tool for the job. Just set up DATA step variables instead. That would let you save separate flags for each person, and report the results pretty easily. Macro variables don't support either of those objectives.

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
  • 9 replies
  • 1416 views
  • 4 likes
  • 4 in conversation