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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Add an else then?

else call symputx('resultscheck', 'passed');

 

edit: note that these comparisons are case sensitive, Failed is not the same as failed.

View solution in original post

6 REPLIES 6
Reeza
Super User
What do you want as the output? How many macro variables? What output exactly?

I'm not sure macro variables are the best option, since you'll have multiple that match the condition so keeping them straight will be a pain.
jawhitmire
Quartz | Level 8

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.

Reeza
Super User

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.


 

jawhitmire
Quartz | Level 8
data work.want;
set work.have end=eof;
retain flag 0;
if PrimaryResultsCount le 5 then do;
Warning=Constituent_Name;
flag=1;
end;
if eof and flag=1 then call symputx('resultscheck','failed');
run;

The problem here is that a call to &resultscheck will fail when Warning is a column full of blanks (ie... none of the data met the condition of less than or equal to 5)
Reeza
Super User

Add an else then?

else call symputx('resultscheck', 'passed');

 

edit: note that these comparisons are case sensitive, Failed is not the same as failed.

jawhitmire
Quartz | Level 8
Thank you. It works perfectly.
Cheers!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 866 views
  • 1 like
  • 2 in conversation