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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.