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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.