Hi,
I'd like to count the number of a specific value ('4') per individual in the second digit of a character variable (one per day) and store the count (new variable). The data set:
pid date1 date2 date3 ...
1 142 121 141
2 111 12B 121
3 141 14A 121
Anyone?
Hope its what you are expecting
data have;
input pid date1$ date2$ date3$;
array cnt(3) cnt1-cnt3;
array dat(3) date1-date3;
do i = 1 to 3;
if substr(dat(i),2,1)='4' then cnt(i)=1;
end;
count=sum(of cnt1-cnt3);
cards;
1 142 121 141
2 111 12B 121
3 141 14A 121
;
Mark the actual answer to the question as correct, not your thankyou post. Now it seems that "Thank you" is the correct answer!
Post test data in the form of a datastep.
We are not here to type it in for your or guess what it should look like.
If you only have one 4 per item then simply:
data have; input pid date1 $ date2 $ date3 $; tmpstr=lengthn(compress(cats(of date:),'4','k')); datalines; 1 142 121 141 2 111 12B 121 3 141 14A 121 ; run;
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.