BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
inquistive
Quartz | Level 8

Hi experts,
I have a dataset which has got 4 characters (alphanumeric) and 10 characters(numeric) ids in the SAME column.
I am trying to separate these into two data sets: one with 4 characters and another with 10 characters.
I need to join the data set with another to fetch other columns for analysis. The second dataset SEPARATE columns with 4 and 10 student ids. So I joined the 4 character student id from first table with 4 character column from second table easily.
But joining two tables to pull the 10 character student id has been a challenge to me.
How to tell sql to pull the student id (from student1) that has got exactly 10 (numeric) characters so that it could be joined on b.stdid (which has 10 numbers)?
```
proc sql;
create table ids as
select
a.id,
b.stdid,
b.lname,
b.fname,
b.mname,
b.subj,
b.stream,
b.gender
from student1 a
join student2 b on a.id= b.stdid
where a.id LIKE '  '

;quit;
```
How to tell proc sql to pull only 10 digit (numeric characters) records only? I could find only wild card characters example on the support forums. I am looking for code to be used within inverted comma( ... a.id LIKE '<what to put here?>'.).

1 ACCEPTED SOLUTION
3 REPLIES 3
maguiremq
SAS Super FREQ

Can you please provide us some example data? You can use this as a guide:

 

https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/

 

You could use the LENGTH function? Like this?

 

data have;
input id :$10. subj :$10.;
datalines;
STUDENT123 Math
STUDENT242 History
STUDENT223 Reading
S123 Science
S456 Technology
STUDENT211 Spanish
;
run;

proc sql;
	create table want as
		select
					*
		from
					have
		where
					length(id) = 10;
quit;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1826 views
  • 3 likes
  • 4 in conversation