Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading part of file into sas

Status
Not open for further replies.

sap1958

Technical User
Oct 22, 2009
138
US
I have the following code
data skipped2;
infile 'c:\6411skipped.txt';
input field $ @;
if field = 'CoreID:' then delete;
input field $8-20;
run;

the actual data looks like this
"CoreID:0000202691"
"CoreID:0000221661"
"CoreID:0000198253"
"CoreID:0000202159"

I only want to read the ID number (ie 0000202691)
I named the variable field with the intention of skipping the CoreID: and beginning with the ID.
How can I do this
 
Is there always a ':' between the words CoreID: and your ID? If the answer is yes I would read the whole line and extract it from the string using a string function. Using your data as an example here is how I would code it.
Code:
data skipped2;
  infile 'c:\6411skipped.txt';
  length mystr $100 MyID $10;
  input mystr &;
  myID = scan(mystr,2,':');
  *** IF YOU WANT TO DROP THE MYSTR VAR FROM YOUR OUTPUT ***;
  DROP mystr;
run;

I hope this helps you.
 
Here is another option to consider:

Code:
data skipped;                        
  length MyID $ 10;                    
  infile 'c:\6411skipped.txt' scanover missover;
  input @ ':' MyID $10.; 
run;

A.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top