DATA Step, Macro, Functions and more

Uanable to run the code with KEEP in SAS 9.4

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Uanable to run the code with KEEP in SAS 9.4

I am using an Excel file in SAS. I ran the following code and it worked.

 

PROC IMPORT OUT = ANALYSIS
DATAFILE="C:\Users\Arushi Arora\Documents\My SAS Files\slumdata.xlsx"
DBMS=XLSX REPLACE; 
RUN;

 

And then I sorted it by ID using the following code

 

PROC SORT DATA= ANALYSIS OUT= ANALYSIS1;
BY ID;
RUN;

 

Since I only wanted to keep a few variables, i used the KEEP statement and the following code.

 

DATA WORK.ANALYSIS1;
KEEP ID ZONE AGE GENDER;
RUN;

 

But it didnt work. The LOG read the following:

 

WARNING: The variable ID in the DROP, KEEP, or RENAME list has never been referenced.
WARNING: The variable ZONE in the DROP, KEEP, or RENAME list has never been referenced.
WARNING: The variable AGE in the DROP, KEEP, or RENAME list has never been referenced.
WARNING: The variable GENDER in the DROP, KEEP, or RENAME list has never been referenced.

 

NOTE: The data set WORK.ANALYSIS1 has 1 observations and 0 variables.

 

 

I dont understand what this means! What code would be relevant to keep the following variables for my analysis?

 

And is it because this data was imported from an EXCEL file? Is there way to convert the Excel file to another format that can be easily read into SAS. I've used CSV and sas extension files before and never faced any issues.

Please help.


Accepted Solutions
Solution
‎06-12-2017 02:46 AM
PROC Star
Posts: 7,364

Re: Uanable to run the code with KEEP in SAS 9.4

You need to use a set statement. Try:

 

DATA WORK.ANALYSIS1;
  set WORK.ANALYSIS1 (KEEP=ID ZONE AGE GENDER);
RUN;

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
Solution
‎06-12-2017 02:46 AM
PROC Star
Posts: 7,364

Re: Uanable to run the code with KEEP in SAS 9.4

You need to use a set statement. Try:

 

DATA WORK.ANALYSIS1;
  set WORK.ANALYSIS1 (KEEP=ID ZONE AGE GENDER);
RUN;

Art, CEO, AnalystFinder.com

 

Occasional Contributor
Posts: 12

Re: Uanable to run the code with KEEP in SAS 9.4

The code worked! Y'all are life Savers! Thanks!

Super User
Posts: 3,113

Re: Uanable to run the code with KEEP in SAS 9.4

You are missing a SET statement reading your data into this step:

 

DATA WORK.ANALYSIS1;
  KEEP ID ZONE AGE GENDER;
  set WORK.ANALYSIS1;
RUN;
Frequent Contributor
Posts: 75

Re: Uanable to run the code with KEEP in SAS 9.4

DATA WORK.ANALYSIS1;

SET ANALYSIS1 (KEEP = ID ZONE AGE GENDER);

RUN;

Occasional Contributor
Posts: 12

Re: Uanable to run the code with KEEP in SAS 9.4

Another question!

 

I want to convert charac variables to numeric for analysis.

In my original dataset, I have gender mentioned as Male and Female and therefore i'm unable to use PROC MEANS or UNIVARIATE.

When i converted female=0 and male= 1 in the original data set, i was able to run these procedures. But it's  cumbersome process since i have 90 other such variables that are in character form.

 

Two questions:

 

1.

How can i convert charac into numeric form in SAS.

 

If i have to convert zones, for example- north, south, east and west to 0,1,2  and 3 respectively, what will the code look like?

 

2.

Is there a way by which i can run Means or univariate or other such commands with the charac variables?

 

 

Super User
Posts: 17,907

Re: Uanable to run the code with KEEP in SAS 9.4

Please mark this question as answered by selecting the answers to your original question and start a new thread for your new question. 

 

In general, see the following links to basic tutorials. 

 

Support.sas.com/training/tutorial

 

These specifially answer your latest question. 

https://stats.idre.ucla.edu/sas/modules/creating-and-recoding-variables-in-sas/

https://stats.idre.ucla.edu/sas/modules/

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 150 views
  • 1 like
  • 5 in conversation