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

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 225 views
  • 1 like
  • 2 in conversation