Hi there,
I have 25 variables with codes (some are missing) and would like to create new columns/variables within specific code range. For example the last column "DiseaseIwant" in the attached "test.xlsx" file has an entry "Yes" because at least one of the 25 columns was coded within the range that I selected, in this case from E10 to E14. (record 4 of Column15 is E102 and is highlighted in yellow therefore "DiseaseIwant" was entered "Yes" for record 4.
could you please help me with the SAS code to get column "DiseaseIwant"?
Thank you.
Would you prefer to define a list of diseases instead of a range, just because your codes are alphanumeric,
then you can try next code:
%let codes = E10 E11 E12 ..... ;
data want;
set have;
array dx $ disease: ;
do i=1 to dim(dx);
if findw("&codes" , dx(i)) > 0 then DiseaseIwant = 'Yes;
else DiseaseIwant = 'No';
end;
run;
Character comparisons in general do not work very well with a "range" of values such a < E14.
You should really provide a complete list of exact values that are the range. Also are you looking for a single similar set of values or do you have a large number? For example could your DiseaseIwant ,or some other varialble, also need some values that start with K, Q and Z?
Thanks for your answer Ballardw,
Yes!, I need to create new variables from alphanumeric codes starting from A to Z but each new variable within a range, for example one new variable will have codes from "C00" to "C979", another one from "C250" to "C254" another column from "E10" to "E14", another column with just "E11" and so on...
some codes in the xlsx table that I attached have 3 or 4 characters, this was a mistake, all should have 4 characters, sorry about this
Also, I just found out that some of the 25 columns in the data sets (each data set with more tha 500,000 rows) where the new variables will be created from have more than one code (up to 5 or 6 codes) so will need a code to scan these extra codes in each of the 25 columns,
It "sounds" complicated and wonder if this can be done?
thank you very much.
Lalohg
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: