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

Im doing sth dumb trying to export this list of No values.  Im trying to use symget so that it makes

if j in ( symget( 'NO_LIST' ) ) then l=1;  become if j in ( 'n','N','no','No','NO','0' ) then l=1;

My thinking is that the symget should cause the macrovariable to be evaluated before the data step code 

and insert it as written which is why its in quotes.   I think the IN operator is the problem but am unsure what else to do.   Thanks.

 

 

 

/*%let NO_LIST=n,N,no,No,NO,0;*/
%let NO_LIST='n','N','no','No','NO','0';

data t1;
j='N';

if j in ( symget( 'NO_LIST' ) ) then l=1;
run;

 

 

%let NO_LIST='n','N','no','No','NO','0';

data t1;
j='N';

if j in ( 'n','N','no','No','NO','0' ) then l=1;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
acordes
Rhodochrosite | Level 12

no need for symget

%let NO_LIST='n','N','no','No','NO','0';

data _null_;
j='N';
if j in ( &NO_LIST) then put "match";
run;

View solution in original post

3 REPLIES 3
acordes
Rhodochrosite | Level 12

no need for symget

%let NO_LIST='n','N','no','No','NO','0';

data _null_;
j='N';
if j in ( &NO_LIST) then put "match";
run;
thryce85
Fluorite | Level 6

feel  dumb now .....   thanks for your help 

ballardw
Super User

When I see something like this my first thought is "the data was read from a poorly controlled source and perhaps should be read with a custom informat."

You can create informats with Proc Format and the invalue statement that will read poorly entered data into standard values. I have one for reading data that should be some form of Yes/No that for a number of reasons I prefer to be numeric 1/0.

 

Here is a brief example:

proc format;
invalue yn (upcase)
'1','Y','YES','T','TRUE' = 1
'0','N','NO','F','FALSE' = 0
' '=.
other=_error_;

data example;
  infile datalines truncover;
  input x :yn.;
datalines;
1
Y
y
Yes
yEs
yeS
YeS
t
truE
0
n
f
falsE
 
abc
;

INVALUE in Proc Format creates informats to read data. The example reads values into a numeric value of 1 or 1. The UPCASE turns the text into upper case before doing the comparison so it handles the stuff with multiple characters allowing for common (and some not so common case of letter issues). The blank is so that missing values are assigned missing and Other=_error_ creates a log entry related to invalid data and assigns missing to the values in the data set. So if you get someone that enters values such as in another language where Non might be used for NO you get details in the log. Change the invalue code to add NON to the appropriate list.

 

Note that similar things can be done with character to character but may take more work.

 

I use custom informats like this because some of my data sources just cannot spell consistently or will add code values without warning. The informats catch those case so I can either change the informat or berate the data source into doing data entry with the approved data value code lists.

 

So perhaps some prevention at reading would remove the need to "fix" later.

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
  • 3 replies
  • 274 views
  • 2 likes
  • 3 in conversation