Learning SAS? Welcome to the exclusive online community for all SAS learners.

SAS Unable to find Data Column in txt

Reply
Occasional Contributor
Posts: 7

SAS Unable to find Data Column in txt

Hi All -  I'm running the following code, SAS found the specified file but is unable to read the datalines, in particular Rent.  When I select the OUTPUTDATA tab, I can see the Gender but none of the other data columns Rent, Utilities, Roommates.  I'm new to SAS, I might be doing something wrong. 

 

data housing;
infile '/folders/myfolders/housing.txt';
input Gender$;
datalines;
Rent
Utilities
Roommates
;
run;
proc means data=housing mean stddev clm;
var Rent;
run;

Super User
Posts: 6,928

Re: SAS Unable to find Data Column in txt

Try this:

data housing;
infile '/folders/myfolders/housing.txt';
input Gender $ Rent Utilities Roommates;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 7

Re: SAS Unable to find Data Column in txt

Thank you! I'm so excited about learning SAS. I greatly appreciate your support and quick response.

I love learning SAS!
Super User
Posts: 6,928

Re: SAS Unable to find Data Column in txt

datalines;

is used to include data in the data step for reading with input (so you don't use an external file).

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 7

Re: SAS Unable to find Data Column in txt

Thank you for the advise. This is my first exposure ever to SAS, I'm
taking a Statistics class and some of the modules available in the class
are not quite clear. I feel like I need to take a separate SAS class for
beginners, I do look forward learning more.

Any recommendations where to start?

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Super User
Super User
Posts: 6,498

Re: SAS Unable to find Data Column in txt

You don't want DATALINES statement in your program, since your data is actually in a separate file that you have already pointed to with the INFILE statement.  Plus your INPUT statement is only listing one variable name and your data file has four columns of data.

You probably want to use this program instead.

data housing;
  infile '/folders/myfolders/housing.txt' truncover;
  input Gender  $ Rent Utilities Roommates ;
run;

The first line tells SAS that you want to start a data step to create the dataset HOUSING. The second line tells SAS where to find the raw data to read.  The TRUNCOVER option will prevent SAS from reading more than one at a time when the line does not have enough values.

The third line tells SAS to read four values from each line. The first one is read a text and the last three are read as numbers.  Since you didn't define the variables in advance SAS will reserve 8 bytes for each of them. The character variable Gender will only be able to hold 8 characters.  The three numeric variables will be stored using the full 64 bit floating point representation that SAS uses for all numbers.

Occasional Contributor
Posts: 7

Re: SAS Unable to find Data Column in txt

Hi Tom - Thank you! I greatly appreciate all the detail, I'm learning new things and I'm truly enjoying it.

I followed your instructions and it worked!

Gracias!
Ask a Question
Discussion stats
  • 6 replies
  • 173 views
  • 0 likes
  • 3 in conversation