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
1 | . | . |
Log:
obs id gcstot
1 | 13 | -1 |
2 | 14 | 14 |
3 | 15 | 14 |
4 | 16 | 15 |
5 | 17 | -2 |
6 | 18 | 15 |
7 | 19 | 15 |
8 | 20 | 15 |
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.
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;
Thanks for your reply. But I have already done that in the previous data step.
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.
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
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
Yes, you need a set statemenet in that last data step. Try ou the code I sent before:
set trs2;
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.
Great. Thanks! I didn't know I need a set statement everytime I use the dataset.
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).
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!
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.
Ready to level-up your skills? Choose your own adventure.