BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I have a dataset (file1), in that I have some 10 to 15 strings. And in another dataset (file2) there are thousands of lines. First, I need to read the first string from the file1 and check for it in all the lines of file2. If the string is present in any line (of file2) then write that line into a new file. Then read the second string from file1 and do the same. Do this for all the strings in file1.

In SAS, how to accomplish this?

Thanks,
Shravan
4 REPLIES 4
Cynthia_sas
SAS Super FREQ
Hi:
You could investigate a PROC SQL join or a SAS data step program MERGE. If you look in the documentation, you will find examples of each of these techniques. Also, there have numerous papers published on these and other similar techniques. You might perform a Google search on performing TABLE LOOKUPs with SAS -- there have been a number of papers that explain how to use the above and other techniques.

cynthia
FredrikE
Rhodochrosite | Level 12
proc sql;
create table new_table as select b.* from
(select string from file1) as a
inner join
(select * from file2) as b
on a.string = b.string
;
quit;

Should do the work!
deleted_user
Not applicable
Hi Fred,

As per your suggestion, I have written the below piece of code to accomplish the task.

Thank you for your help.

DATA DCOL;
KEEP DSN VOLSER;
INFILE DCOLLECT;
INPUT @5 RECTYPE $1.
@25 DSN $44.
@79 VOLSER $6. ;
IF RECTYPE = 'D';
********************************************************************
*** CREATE THE INPUT DATASET MISCLST FROM DCOLLECT MISCDSN MEMBER***
********************************************************************;
DATA MISCLST;
KEEP MISCDSN LEN;
INFILE LST;
INPUT @1 MISCDSN $44. ;
LEN = LENGTH(MISCDSN);
********************************************************************
*** JOIN DCOLLECT REPORT AND MISCDSN MEMBER ***
********************************************************************;
PROC SQL;
CREATE TABLE NEW_TABLE AS SELECT * FROM
(SELECT A.DSN, A.VOLSER
FROM DCOL A, MISCLST B
WHERE INDEX(A.DSN,(SUBSTR(B.MISCDSN,1,B.LEN))) > 0)
ORDER BY VOLSER
;
QUIT;
PROC PRINT DATA=NEW_TABLE;
DATA OUT;
SET NEW_TABLE;
FILE OUTDD;
PUT @1 DSN @46 VOLSER;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
For what its worth, a somewhat simpler WHERE coding technique supported by PROC SQL is shown below:

WHERE A.DSN CONTAINS TRIM(B.MISCDSN)

Scott Barry
SBBWorks, Inc.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 895 views
  • 0 likes
  • 4 in conversation