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


try:


data list;
input fname $ id $;
cards;
1122 bg
1620 bg
1660 bg
0520 tz
0240 tr
0280 tr
0560 tr
;run;

data have;
input o fname $   id $;
cards;

                        1     1122     bg   
                        2     1620     bg   
                        3     1660     bg   
                        4     0240     tr   
                        5     0280     tr   
                        6     0560     tr   
                        7     0520     tz   
                        8     1122     tz 
      ;
     

proc sql;
create table final_selection as
select a.*
from have a,list b
where a.fname=b.fname and a.id=b.id;
  quit;
proc print;
run;
                                       Obs    o    fname    id

                                        1     1    1122     bg
                                        2     2    1620     bg
                                        3     3    1660     bg
                                        4     4    0240     tr
                                        5     5    0280     tr
                                        6     6    0560     tr
                                        7     7    0520     tz

tesu
Calcite | Level 5

Thanks, Linlin. Your code solves the problem.

Ksharp
Super User

Sorry. My bad. Linlin, you win.

proc sql;

select path

  from have

   where catx(' ', fname, id)  in (select catx(' ', fname,id)  from list);

quit;

Linlin
Lapis Lazuli | Level 10

:smileylaugh::smileylaugh::smileylaugh:!

tesu
Calcite | Level 5

Thanks, guys! You're amazing!

tesu
Calcite | Level 5

Thanks for getting back to the discussion. I've learned a lot from you!

Tom
Super User Tom
Super User

I am not sure what the issue is.  Just check if f2\0222 is in the filenames.  Probably would be easier to see the solution if the columns in your CSV file were in the same order as they appear in the filenames.

data filelist ;

  input fname $ folder $ @@;

cards;

0222 f2 0345 f2 2345 f1 3423 f3 4444 f1 4827 f3 5635 f3 6767 f1 7623 f3

run;

data filenames;

  infile 'dir *.dbf /s/b' pipe truncover;

  input path $80.;

run;

proc sql noprint ;

  create table want as select * from filenames

    where catx('\',scan(path,-2,'\'),scan(path,-2,'.\')) in

     (select catx('\',folder,fname)) from filelist)

  ;

quit;

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!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 21 replies
  • 1543 views
  • 6 likes
  • 6 in conversation