BookmarkSubscribeRSS Feed
YW_CA
Calcite | Level 5


hi, I have dataset, for example like this:

data NAME1;

infile datalines delimiter=",';

input name $ gender $ age;

datalines;

AB,F,1

CD,M,2

XX,F,2

OO,M,3.5

PP,F,2

AC,F,2

;

RUN;

I have a prompt value (NAMA_SELECTED) which user enter names. So if user enter ALL, all or leave it blank, I want to export all the records to the dataset SELECTED_PEOPLE. If user enter AB and/or CD only, these two records should be exported to SELECTED_PEOPLE dataset.

I use %_eg_whereParam for subsetting when user enter AB. and/or CD, not problem. But when it come to check if the prompt value is ALL, or all or blank, it just cannot output everything. I am using if "&NAMA_SELECTED" = 'ALL' or "&NAMA_SELECTED" = 'all' or "&NAMA_SELECTED" = ' ' then do; output;end;

What's wrong this logic?

8 REPLIES 8
Reeza
Super User

Post your full code.

YW_CA
Calcite | Level 5

here is step for subsetting:

data selected_names;

set NAME1;

if "&NAME_SELECTED" = 'ALL' or "&NAME_SELECTED" = 'all' or "&NAME_SELECTED" = ' ' then do;

output;

end;

else do;

where %_eg_whereParam(name, NAME_SELECTED,IN,TYPE=S);

end;

run;

ballardw
Super User

Slight improvement but depending on people may be usefule:

if upcase("&NAME_SELECTED") = 'ALL'

will handle ALL, All, aLL, alL, all and others.

YW_CA
Calcite | Level 5

does not work. From the log, the step took the if as where and did the  where NAME = 'ALL' logic, which is similar to what I've seen before.

YW_CA
Calcite | Level 5

interesting, if I comment out the else do logic. just leave the first if  end in the datastep. it export all the records.

data selected_names;

set NAME1;

if "&NAME_SELECTED" = 'ALL' or "&NAME_SELECTED" = 'all' or "&NAME_SELECTED" = ' ' then do;

output;

end;

else do; /*

where %_eg_whereParam(name, NAME_SELECTED,IN,TYPE=S);

OUTPUT;*/

end;

run;

Tom
Super User Tom
Super User

WHERE statement is applied before the data is read into the data step.  Placing it inside of a conditional does not change this.

Use IF statement instead if you want to apply the filter conditionally.

Vladislaff
SAS Employee

%macro filter;

data selected_names;

set NAME1;

%if %upcase(&NAME_SELECTED) ^= ALL and &NAME_SELECTED ne %then %do;

where %_eg_whereParam(name, NAME_SELECTED,IN,TYPE=S);

%end;

run;

%mend;

%filter;

deleted_user
Not applicable

Use If and else if instead of else and where

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1484 views
  • 0 likes
  • 6 in conversation