Learning SAS? Welcome to the exclusive online community for all SAS learners.

Recoding data

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Recoding data

Ive been trying to recode data that is stored in my excel file. I am using SAS University Edition and used the command to import the excel sheet as follows. The name of my excel sheet is "symptoms"

/* Generated Code (IMPORT) */

/* Source File: symptoms.xlsx */

/* Source Path: /folders/myfolders/sasuser.v94 */

/* Code generated on: 6/15/17, 8:00 PM */

 

%web_drop_table(WORK.IMPORT);

 

FILENAME REFFILE '/folders/myfolders/sasuser.v94/symptoms.xlsx';

 

PROC IMPORT DATAFILE=REFFILE

            DBMS=XLSX

            OUT=WORK.IMPORT;

            GETNAMES=YES;

            SHEET="Master";

RUN;

 

PROC CONTENTS DATA=WORK.IMPORT; RUN;

 

%web_open_table(WORK.IMPORT);

 

Everything works fine and I've been able to get some descrptive data by using the using the commands below

proc freq data=WORK.IMPORT;

tables sex Fever Diarrhoea see pain sad ;

run;

proc univariate data=work.import plot;

var age cd4 cd4_recent;                                            

run;

proc means data=work.import;

var age cd4 CD4_recent;

run;

 

The issue arises when im trying to recode the varibles, but i cant get past naming and setting the " set project." command. I've read that we are supposed to use the LIBNAME comand as follows to use the recode command but i keep getting an error as follows 

 

libname project '/folders/myfolders/sasuser.v94/';

data work.import;

set project.symptoms;

run;

 

            libname project '/folders/myfolders/sasuser.v94/';

 NOTE: Libref PROJECT refers to the same physical library as SASUSER.

 NOTE: Libref PROJECT was successfully assigned as follows:

       Engine:        V9

       Physical Name: /folders/myfolders/sasuser.v94

 63         data work.import;

 64         set project.symptoms;

 ERROR: File PROJECT.SYMPTOMS.DATA does not exist.

 65         run;

 

 NOTE: The SAS System stopped processing this step because of errors.

 WARNING: The data set WORK.IMPORT may be incomplete.  When this step was stopped there were 0 observations and 0 variables.

 WARNING: Data set WORK.IMPORT was not replaced because this step was stopped.

 NOTE: DATA statement used (Total process time):

       real time           0.01 seconds

       cpu time            0.01 seconds

 

data work.import;

set project.symptoms;

if sex = '1' then sexes ='Male';

if sex = '2' then sexes ='z-female';

 

if fever ='1' then feve= 'never';

if fever ='2' then feve= 'less than 1 day';

run;

 

Can ayone help me figure out what im doing wrong? Thanks! 

 


Accepted Solutions
Solution
‎06-16-2017 02:20 PM
PROC Star
Posts: 7,468

Re: Recoding data

Posted in reply to UGAstudent

No, you don't need to have a libname statement to be able to recode data. And, your data ISN't in your sasuser library, it's in your work library.

 

You could just start your recoding data step with:

data import;

  set import;

 

If you don't specify the libname, the libname WORK is assumed.

 

However, look at the output from your proc contents before proceding. Are sex and fever numeric variables or character variables? That will be important as you can't treat a numeric variable as if it was a character variable, or visa versa.

 

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
Solution
‎06-16-2017 02:20 PM
PROC Star
Posts: 7,468

Re: Recoding data

Posted in reply to UGAstudent

No, you don't need to have a libname statement to be able to recode data. And, your data ISN't in your sasuser library, it's in your work library.

 

You could just start your recoding data step with:

data import;

  set import;

 

If you don't specify the libname, the libname WORK is assumed.

 

However, look at the output from your proc contents before proceding. Are sex and fever numeric variables or character variables? That will be important as you can't treat a numeric variable as if it was a character variable, or visa versa.

 

Art, CEO, AnalystFinder.com

 

Occasional Contributor
Posts: 8

Re: Recoding data

Thank you so much! this helped a lot!
☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 213 views
  • 0 likes
  • 2 in conversation