Hello there,
I am new user, and got stock in a question which I couldnt get it to run on SAS, any help appreciated.
the question:
keep dmage mrace dmar dlivord dfage frace csex dbirwt primac wtgain;
thank you so much in advance
Hi:
There are a few things wrong with your program. Here's a hint about one of them that should be generating errors. If you are going to reference a dataset in a procedure step you need data= -- so, for example, consider the difference in your PROC SORT versus your PROC PRINT. One is right and the other is not:
In your program, I recommend that you look up the difference between a KEEP statement and a KEEP= option and then correct your syntax accordingly. Also, what is the purpose of the main=csex; assignment statement? Are you trying to create a new variable or column called MAIN by assigning the current value of the variable CSEX? Why is the name of the variable the same as the name of the dataset you are creating? What is this statement really doing and is it doing what you need to do??
Hope this helps,
Cynthia
Show us what you have tried so far.
this is what i have tried, I know it is not correct so please excuse me.
data main;
set small;
if csex = '1';
keep dmage mrace dmar dlivord dfage frace csex dbirwt primac wtgain;
run;
input dmage mrace dmar dlivord dfage frace csex dbirwt primac wtgain;
proc print data = small (obs 10);
run;
What purpose do you think that third to last line is doing?
You don't seem to have anything that will sort the data as requested. How do you propose to sort the data?
okay so I was trying a little and this is what i got
title 'Lab 6 – Problem 5';
data main;
set small (keep dmage mrace dmar dlivord dfage frace csex dbirwt primac wtgain);
main = csex;
proc sort main;
by csex;
run;
proc print data = main;
run;
thanks
Hi:
There are a few things wrong with your program. Here's a hint about one of them that should be generating errors. If you are going to reference a dataset in a procedure step you need data= -- so, for example, consider the difference in your PROC SORT versus your PROC PRINT. One is right and the other is not:
In your program, I recommend that you look up the difference between a KEEP statement and a KEEP= option and then correct your syntax accordingly. Also, what is the purpose of the main=csex; assignment statement? Are you trying to create a new variable or column called MAIN by assigning the current value of the variable CSEX? Why is the name of the variable the same as the name of the dataset you are creating? What is this statement really doing and is it doing what you need to do??
Hope this helps,
Cynthia
THANK YOU SO MUCH!
I ran it now and it worked, sorry I just started to learn SAS and I am still new in this, I really appreciate your help Cynthia!
Data small;
Set main;
keep dmage mrace dmar dlivord dfage frace csex dbirwt primac wtgain;
run;
proc sort data = small;
by csex;
run;
proc print data = small (obs = 10);
run;
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!
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.