BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NewUsrStat
Lapis Lazuli | Level 10

Hi guys, suppose to have the following two datasets: 

 

data set1;
input Variable1;
cards;
71515

48041

85201

51881

4329

85220

;
run;

 

 

data set2;
input MyVariable;
cards;
390

852

715

411

465

517

;
run;

 

Is there a way to subset from set1 basd on the list in set 2? Required match: first 3 numbers (so all) in set2 MUST match at the beginning the first 3 numbers in Varibale1 from set 1. 

Note: numbers in set2 are always composed by 3 integers. Thank you in advance.

 

Desired output: 

data Output;
input Variable_output;
cards;

71515

85201

85220

;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
proc SQL;
     select varlabel1 from set1 
     where substr(varlabel1,1,3) in (select distinct myvariable from set2);
quit;
--
Paige Miller

View solution in original post

1 REPLY 1
PaigeMiller
Diamond | Level 26
proc SQL;
     select varlabel1 from set1 
     where substr(varlabel1,1,3) in (select distinct myvariable from set2);
quit;
--
Paige Miller

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 666 views
  • 1 like
  • 2 in conversation