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


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;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

2 REPLIES 2
Astounding
PROC Star

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.

PGStats
Opal | Level 21

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

PG

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 729 views
  • 5 likes
  • 3 in conversation