BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
anming
Pyrite | Level 9

Column and formatted inputs to load a file are similar but different. 

 

When you load the following datasheet test.txt,

 

Name Sex DOB Weight

12345678901234567890

John  M08/10/202060

 

For column input

Data test.col;

infile "path/test.txt";

input

name $1-5

sex $6

DOB $7-16

Weight 17-18;

run;

you will get DOB in character. You can use input to convert the character to numeric of DOB before the calculation with DOB.

 

But if you use formatted input:

 

Data test.col;

infile "path/test.txt";

input

@1 name $5.

@6 sex $1.

@7 DOB mmddyy10.

@17 Weight 2.;

run;

you will get the numeric DOB.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ
Hi:
Go to the documentation and read about the differences between column input and formatted input. With column input you can ONLY read character or numeric data in standard format. Your date is NOT in a standard format (has slashes), so it CANNOT be read except as a character string in the first program. That is the "side effect" of using column input. Either list input or formatted input, as you show could read the data with an informat. LISTING input won't work in this case because it looks like your data is not separated by a delimiter. So your only choice IF you want to read DOB as numeric is formatted input. If you look in the documentation on COLUMN input: https://go.documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=lestmtsref&docsetTarge... you'll see that it specifically tell you that you can ONLY read standard numeric form with COLUMN based input.
Cynthia

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

You cannot use any special informats when using column ranges.  But you can mix formatted input and column ranges in the same INPUT statement.

input
  name $1-5
  sex $6
  @7 DOB mmddyy10.
  Weight 17-18
;

 

Cynthia_sas
SAS Super FREQ
Hi:
Go to the documentation and read about the differences between column input and formatted input. With column input you can ONLY read character or numeric data in standard format. Your date is NOT in a standard format (has slashes), so it CANNOT be read except as a character string in the first program. That is the "side effect" of using column input. Either list input or formatted input, as you show could read the data with an informat. LISTING input won't work in this case because it looks like your data is not separated by a delimiter. So your only choice IF you want to read DOB as numeric is formatted input. If you look in the documentation on COLUMN input: https://go.documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=lestmtsref&docsetTarge... you'll see that it specifically tell you that you can ONLY read standard numeric form with COLUMN based input.
Cynthia

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 558 views
  • 1 like
  • 3 in conversation