Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- KEEP more then 2 variables in "IF_N_ = 1 THEN SET ...

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-03-2013 04:52 PM

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;

Accepted Solutions

Solution

08-03-2013
06:12 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-03-2013 06:12 PM

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.

All Replies

Solution

08-03-2013
06:12 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-03-2013 06:12 PM

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.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-03-2013 06:12 PM

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