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.
You need to use a set statement. Try:
DATA WORK.ANALYSIS1; set WORK.ANALYSIS1 (KEEP=ID ZONE AGE GENDER); RUN;
Art, CEO, AnalystFinder.com
You need to use a set statement. Try:
DATA WORK.ANALYSIS1; set WORK.ANALYSIS1 (KEEP=ID ZONE AGE GENDER); RUN;
Art, CEO, AnalystFinder.com
The code worked! Y'all are life Savers! Thanks!
You are missing a SET statement reading your data into this step:
DATA WORK.ANALYSIS1;
KEEP ID ZONE AGE GENDER;
set WORK.ANALYSIS1;
RUN;
DATA WORK.ANALYSIS1;
SET ANALYSIS1 (KEEP = ID ZONE AGE GENDER);
RUN;
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?
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/
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.