09-19-2017 03:20 PM
I try to simiply my program.
I have this program and it works.
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;
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?
09-19-2017 03:35 PM
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.
09-19-2017 04:00 PM
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;
09-19-2017 04:47 PM
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.);
09-19-2017 04:53 PM - edited 09-19-2017 04:54 PM
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 ...