BookmarkSubscribeRSS Feed
jc3992
Pyrite | Level 9

Hello everyone,

 

I have a data set with a variable "Age" looking like this:

Age

10-14

10-14

15-19

.

.

.

 

It is a tab-delimited data, so I use the code as below:

 

infile "&dirdata.SAS_Test/file_name.txt" delimiter="09"x DSD truncover firstobs=2;

But the printout would be a typo between 10 and 14 for the variable "Age",

and influence my following analysis as SAS would complain for invalid symbol.

 

Thank you very much for all the suggestions!

Thanks!

2 REPLIES 2
PGStats
Opal | Level 21

You should be able to read such data with:

 

data myData;
infile "&dirdata.SAS_Test/file_name.txt" delimiter="09"x DSD truncover firstobs=2;
input age$  /* other fields */;
run;

the $ tells SAS that age is a character variable.

PG
Cynthia_sas
Diamond | Level 26

Hi:

  Your INPUT statement is more important in this case than you INFILE statement. Are you trying to read age as a numeric variable or as a character variable? The value 10-14 is NOT valid as a numeric value. You need to read it as character. I doubt that age is the only value in your data. When I made a small test file that is tab delimited with just name and age columns, I was able to read the age value correctly by using the program shown below:

read_hyphen.png

Hope this helps,

Cynthia

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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