Hello,
I try to simiply my program.
I have this program and it works.
=====================================================
data new_data;
set old_data;
array old_code[*] old_code1-old_code25;
array new_code[*] new_code1-new_code25;
do i = 1 to 25;
old_code[i]= compress(old_code[i], '.') ;
if old_code[i] in: ('E10','E11','E12','E13','E14') then new_code[i]=1;
else new_code[i]=0;
end;
output;
======================================================
I thought that I could replace ('E10','E11','E12','E13','E14') with ('E40':'E14').
But I got an error message:
"ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant,
a datetime constant, a missing value, iterator, (, ), ','."
In my real dataset, I have to list more like E10 to E90. So, it would be nice if there is a way to make programming easy.
I appreciate your suggestions.
Oh, and for the above example, I understand that 'E10' following in: means any string starting with E10.
Am I correct?
Thank you,
Yoko
If you're criteria is matching the first three characters, then substr the first three characters and make your comparison. Unfortunately I think you're stuck typing it out because the list is character and ranges for characters aren't a good idea in my experience.
You can use a macro to generate the list. The following step llustrates:
data _null_;
%macro e; %do i = 10 %to 90; "E&i" %end; %mend;
x = 'E20';
if x in (%e) then put 'Yes 20';
x = 'E201';
if x in (%e) then put 'no 201';
run;
Can't test it now, but maybe creating a format helps.
Proc format;
InValue narf
'E10'-'E90' = 1
Other = 0;
Run;
In the datastep: new_code[i] = input(old_code[i], narf.);
@Yoko if your problem is solved please mark the correct solution as the answer/solution.
Or, use some base functions - this would likely be considered old fashioned. I'm sure a PRX solution is better but I avoid those like the plague.
1. Check if first character is E
2. Check if next two characters are in 10:90
if char(character_variable, 1) = 'E' and input(substr(character_variable, 2, 2), 8.) in (10:90) then do ...
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.