Hi,
I have around 80 columns (Col1 to Col80). These columns have city names. I need to look through all columns and see if there in city 'London'.
I have done this by Concatinating the column values and looking for string 'London' but I am hoping there must be an easier way.
The other alternative I was thinking was arrays but I don't want to create another 80 variables or change the values of existing ones.
Thanks as always.
S
Hi,
Well, you don't need to create new variables in the array:
data have;
col1="New York"; col2="London"; output;
run;
data want;
set have;
array col{2};
if find(cats(of col{*}),"London")>0 then Flag="Y";
run;
Yet other ways ..
data _null_;
set have;
array k _character_;
if 'London' IN k then put 'Found';
run;
You can use:
whichC('London', of k
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.