SAS Community-
Using a large dataset, there is the numeric variable - 'SubjectID'. Within 'SubjectID' the observations including a number of different lengths. For example some SubjectID observations have 6 numbers while others have 7 or 8 numbers.
SubjectID
234583
5546492
5546489
234577
68907734
68907736
234581
Please advise on a SAS function that will inform me on how many Subject IDs have 6 for a number length, 7th for a number length and 8 for a number length.
Eventually, I will use this information to for a substring.
Thanks!
Hope this will get you started:
data have;
input SubjectID $8.;
len=length(subjectid);
cards;
234583
5546492
5546489
234577
68907734
68907736
234581
;
proc freq data=have;
table len;
run;
Regards,
Haikuo
Hope this will get you started:
data have;
input SubjectID $8.;
len=length(subjectid);
cards;
234583
5546492
5546489
234577
68907734
68907736
234581
;
proc freq data=have;
table len;
run;
Regards,
Haikuo
Haikuo-
One quick follow-up question, how do I do this step without using the input statement?
I want to use a dataset currently located in my work library. According to proc contents for this dataset, the subject id has the variable listed as numeric with 6 as the length (though I know there are subject ids with up to 9 numbers).
I'm sure this is a very simple SAS 101 question. I just can't seem to get my head around it.
Thanks.
I hope the following will help you with your problem:
/*This to input the numberic value*/
data have;
input SubjectID ;
cards;
234583
5546492
5546489
234577
68907734
68907736
234581
;
data want;
set have;
len=length(strip(subjectid));
/*This to get the occupied length*/
run;
proc freq data=want;
table len;
run;
If the values are numeric the length refers to the number of bytes used to store the value. The range for length of numerics is 3 to 8. This might do what you need.
data len;
set <your dataset>;
len = length (put(SubjectId,f10.0));
run;
proc freq;
table len;
run;
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 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.