Hello,
When running the following SAS syntax, I found that I can keep maximum two variables (e.g., x1, x2) using "KEEP" after IF .... THEN.... if I keep three or more variables, only two variables have values and other variables are with missing values. Could anyone please tell me how to keep three or more variables?
DATA case_control;
IF_N_ = 1 THEN SET case (keep = x1 x2 RENAME (x1=height_case x2 = weight_case));
SET control;
diff1 = height_case - height;
diff2 = weight_case - weight;
RUN;
SAS doesn't limit the variables you can read in, so the problem lies elsewhere.
I assume that you have already checked the data set CASE to make sure that the values you bring in are not missing to begin with.
So the problem likely lies in CONTROL. If that data set also contains the additional variables (and has missing values for them), you would get the results you are observing.
Good luck.
SAS doesn't limit the variables you can read in, so the problem lies elsewhere.
I assume that you have already checked the data set CASE to make sure that the values you bring in are not missing to begin with.
So the problem likely lies in CONTROL. If that data set also contains the additional variables (and has missing values for them), you would get the results you are observing.
Good luck.
It could be that the control dataset overwrites some of your variables. Your example, once fixed for the typos (space between IF and _N_ and = after RENAME), works just fine, even with and extra variable in the case dataset.
data case;
x1=1; x2=2; x3=3;
run;
data control;
input height weight;
datalines;
10 100
20 200
30 300
;
DATA case_control;
IF _N_ = 1 THEN SET case (keep = x1 x2 x3 RENAME=(x1=height_case x2 = weight_case x3=test));
SET control;
diff1 = height_case - height;
diff2 = weight_case - weight;
RUN;
proc print; run;
PG
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.