DATA Step, Macro, Functions and more

SAS not able to read data

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

SAS not able to read data

I have a dataset with the variable id and gcstot ( numerical score). Everytime I am trying to create a new variable using gcstot its giving me an error message that gcstot is uninitiated, even though its already there on the original dataset. The original dataset is as below. I am trying to run the code

data trs2;
gcs = gcstot*2;
run; 

It is giving me the output as 

             gcstot    gcs                       
1..

 

Log:

Variable gcstot is uninitialized.
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line)Smiley SadColumn).
1 at 57:13
 
Dataset

obs          id          gcstot

113-1
21414
31514
41615
517-2
61815
71915
82015

Accepted Solutions
Solution
‎02-24-2017 09:38 AM
Frequent Contributor
Posts: 75

Re: SAS not able to read data

You can also combine the last two data steps into one, like this:

data trs2;
set trs1;
gcs = gcstot*2;
keep inc_key gcstot gcs;
run;

You do not need to do the calculation in a brand new data step.

 

View solution in original post


All Replies
Frequent Contributor
Posts: 75

Re: SAS not able to read data

Your data step does not have a set statement which is required if you are trying to read in data from a certain dataset. The data statement specifies which dataset to *write* out to, it does not read data. This is what you need:

data trs2;
set trs2;
gcs = gcstot*2;
run; 
New Contributor
Posts: 4

Re: SAS not able to read data

Thanks for your reply. But I have already done that in the previous data step. 

Frequent Contributor
Posts: 75

Re: SAS not able to read data

You have to specify a set statement every time you are trying to read a dataset (i.e. in each new data step). Not just once.

Super Contributor
Posts: 408

Re: SAS not able to read data

Haha likely the title "SAS not able to read data" is the most tantalizing of all as that would be a first. In my 30 years of SAS that has not yet happened.

 

Luckily in this case it will also not happen ;-)

 

What we see is a datastep where you forgot to refer to an input dataset. Now your variable gcstot was never given a value. The result makes sense: a missing value (the dot) for both gcstot and gcs.

 

I think you meant to code

 

data trs2;
set yourinput;
gcs = gcstot*2;
run; 

When yourinput contains variable gcstot that will be read and the clculation will yield a non-missing value.

 

Regards Jan

New Contributor
Posts: 4

Re: SAS not able to read data

Hi,

 

Thanks for your contribution. This is my SAS code what I am trying to run. I don't really see a problem with set statement here. 

 

proc import out = triss1
datafile = "/home/srawanisarkar0/sasuser.v94/triss1.csv"
DBMS = csv replace;
getnames = yes;
run;

 

data trs1;
set triss1;
run;

 

proc means data = trs1;
var gcstot;

 

data trs2;
set trs1;
keep inc_key gcstot;
run;

 

data trs2;
gcs = gcstot*2;
run;

 

Regards,

shr

Frequent Contributor
Posts: 75

Re: SAS not able to read data

Yes, you need a set statemenet in that last data step. Try ou the code I sent before:

 

set trs2;
Solution
‎02-24-2017 09:38 AM
Frequent Contributor
Posts: 75

Re: SAS not able to read data

You can also combine the last two data steps into one, like this:

data trs2;
set trs1;
gcs = gcstot*2;
keep inc_key gcstot gcs;
run;

You do not need to do the calculation in a brand new data step.

 

New Contributor
Posts: 4

Re: SAS not able to read data

Great. Thanks! I didn't know I need a set statement everytime I use the dataset.  

Frequent Contributor
Posts: 75

Re: SAS not able to read data

In most data steps, you have to specify where your data should be read from and where it should be written out to (there are some exceptions like data _null_, but that is besides the point right now). The data statement only specifies where to *write* to, you need a set or an input statement to specify where to *read* the data from. No data to read in = no data to write out (unless you are generating data in that very data step).

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 174 views
  • 3 likes
  • 3 in conversation