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

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):(Column).
1 at 57:13
 
Dataset

obs          id          gcstot

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

Accepted Solutions
nehalsanghvi
Pyrite | Level 9

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

9 REPLIES 9
nehalsanghvi
Pyrite | Level 9

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; 
Shravani0
Calcite | Level 5

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

nehalsanghvi
Pyrite | Level 9

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.

jklaverstijn
Rhodochrosite | Level 12

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

Shravani0
Calcite | Level 5

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

nehalsanghvi
Pyrite | Level 9

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

 

set trs2;
nehalsanghvi
Pyrite | Level 9

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.

 

Shravani0
Calcite | Level 5

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

nehalsanghvi
Pyrite | Level 9

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).

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 9 replies
  • 2979 views
  • 3 likes
  • 3 in conversation