BookmarkSubscribeRSS Feed
Rhino84
Fluorite | Level 6

Hi All,

 

I have a txt file and i need to pick only the first value from the txt file in sas.

 

This is how the txt file header looks like:

 

ACC_ID   Name   Address  phone_no  email  country

 

I want to extract just the ACC_ID data from this text file. The file is not delimited and the ACC_ID field is a numerical field (eg: 234908, 789087, 783420 etc)

 

3 REPLIES 3
Kurt_Bremser
Super User

We need to see your original data as is, not a description.

Open your text file with a text editor (e.g. Notepad) and copy/paste the first few lines into a window opened with this button:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

Ksharp
Super User
Can you post some real data, so we can test the code .
Tom
Super User Tom
Super User

@Rhino84 wrote:

Hi All,

 

I have a txt file and i need to pick only the first value from the txt file in sas.

 

This is how the txt file header looks like:

 

ACC_ID   Name   Address  phone_no  email  country

 

I want to extract just the ACC_ID data from this text file. The file is not delimited and the ACC_ID field is a numerical field (eg: 234908, 789087, 783420 etc)

 


As long as each ACC_ID does not contain any spaces and there is at least one space between the ACC_ID and the NAME value then a simple INPUT statement should work fine.

You claim ACC_ID is numerical but why would you store an ID variable as a number?  The Mean or Standard Deviation of an ID has no meaning.

 

data want;
  infile 'myfile.txt' firstobs=2;
  input acc_id :$10.;
run;

The FIRSTOBS=2 option on the INFILE statement is to skip the header row.

The : modifier before the informat is to make sure the INPUT only reads the first word on the line.

If you really need to make ACC_ID as numeric then just remove the :$10. from the INPUT statement.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 845 views
  • 0 likes
  • 4 in conversation