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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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