Hello,
I have a data looks like this below. I would like to count number of times substring 'Id' appeared in the variable Practise. I tried below code but it does not work, my code generates only 0.
Raw Data:
| Practise |
| Id: John, Id: Kerstin, Name: sunny, |
| Name: Kane, Id: Rohan |
| Id: Ranson, Name: X_, Id: Stary |
Id:Ata, Name: Unknown, Id: Aka, Name, Unknown, Id: Prx |
Expected Result:
| Practise | Id_Count |
| Id: John, Id: Kerstin, Name: sunny, | 2 |
| Name: Kane, Id: Rohan | 1 |
| Id: Ranson, Name: X_, Id: Stary | 2 |
| Id:Ata, Name: Unknown, Id: Aka, Name, Unknown, Id: Prx | 3 |
My SAS code:
data samp ;
set Clean;
count_Id = count(Practice, 'Id:');
put count_Id;
run;
@chapidi99 What doesn't work? Your code appears to return the expected result for your sample data.
data have;
infile datalines truncover dlm='|';
input Practise :$100. count_expected;
datalines;
Id: John, Id: Kerstin, Name: sunny,|2
Name: Kane, Id: Rohan|1
Id: Ranson, Name: X_, Id: Stary|2
Id:Ata, Name: Unknown, Id: Aka, Name, Unknown, Id: Prx|3
;
data want;
set have;
count_Id = count(Practise, 'Id:');
count_derived_1=count(Practise,'id:','i');
run;
@chapidi99 What doesn't work? Your code appears to return the expected result for your sample data.
data have;
infile datalines truncover dlm='|';
input Practise :$100. count_expected;
datalines;
Id: John, Id: Kerstin, Name: sunny,|2
Name: Kane, Id: Rohan|1
Id: Ranson, Name: X_, Id: Stary|2
Id:Ata, Name: Unknown, Id: Aka, Name, Unknown, Id: Prx|3
;
data want;
set have;
count_Id = count(Practise, 'Id:');
count_derived_1=count(Practise,'id:','i');
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.