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
SAS Super FREQ

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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