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....
ddd
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
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
@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.
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.
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.
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
@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.
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?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.