SAS Version 9.4
data work.eqn32;
input DFLAW_Activity_Analyte 9.8 @13 Constituent_Name $20. @29 ResultsCount
@32 PrimaryResultsCount ;
datalines;
0.0000001 American 8 6
0.0003333 American 0 1
0.0275245 Ceiling 7 6
0.0000011 Baltimore 7 6
0.0444444 Curry 5 4
0.0055555 Canary 8 6
0.0000026 Europe 7 6
0.0055552 Neptune 7 6
0.0001111 Platonic 8 6
0.0000001 Playtown 8 6
0.0002222 Pluto 8 6
0.0033322 Plumbing 12 10
0.0001146 Stronghold 8 6
0.0000188 Tigerland 8 6
0.0000112 Unbrella 7 6
0.0007777 Underwear 7 6
;
run;
If PrimaryResultsCount is less than 6 (happens where Constituent_Name is either American and Curry), I need to create a macro 'flag' that may be used later to warn the user. I'd also like to retain the corresponding Constituent_Names that do not meet the condition.
This is what I have so far - but it's not working:
data work.want;
set work.eqn32 end=eof;
N+1;
array char[*] _character_;
array c_count[100] _temporary_ (100*0);
if PrimaryResultscount le 5 then warning=constituent_name;
do i = 1 to dim(char);
if missing(char[i]) then c_count[i] + 1;
end;
if eof then do;
do i = 1 to dim(char);
Variable = vname(char[i]);
NMiss = c_count[i];
NHave=N-NMiss;
if NHave ne N then call symputx('Flag',"Missing Data");
else call symputx('Flag',"Complete Data");
output;
end;
end;
keep Variable N NMiss NHave ;
run;
%put &Flag;
Thank you for the support.
Jane
Add an else then?
else call symputx('resultscheck', 'passed');
edit: note that these comparisons are case sensitive, Failed is not the same as failed.
Thank you for the feedback.
Avoiding the macro is definitely an option.
The following code would simply put another column with then names of constituents where the condition (less than or equal to 5) is met:
data work.want
set work.have;
if PrimaryResultsCount le 5 then Warning=Constituent_Name;
run;
The column variable, Warning, may be full of blanks. If not, I would like to create a macro variable that will tell the user that there are constituents that do not meet the condition somewhere within the data.
What about an overall flag in addition to your warning then?
data work.want
set work.have END=EOF;
retain flag 0;
if PrimaryResultsCount le 5 then do;
Warning=Constituent_Name;
flag=1;
end;
*creates macro variable;
If EOF then call symputx('resultsCheck', 'Failed');
run;
%put ResultsCheck = &resultsCheck;
%if &resultsCheck = Failed %then %do;
%PUT WARNING: XYX has errors;
%end;
@jawhitmire wrote:
Thank you for the feedback.
Avoiding the macro is definitely an option.
The following code would simply put another column with then names of constituents where the condition (less than or equal to 5) is met:
data work.want
set work.have;
if PrimaryResultsCount le 5 then Warning=Constituent_Name;
run;
The column variable, Warning, may be full of blanks. If not, I would like to create a macro variable that will tell the user that there are constituents that do not meet the condition somewhere within the data.
Add an else then?
else call symputx('resultscheck', 'passed');
edit: note that these comparisons are case sensitive, Failed is not the same as failed.
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.