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)
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:
@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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.