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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

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
  • 2348 views
  • 0 likes
  • 3 in conversation