I am trying to run this code but it won't recognize the percentages so every answer is coming out at Yes for selective.
DATA University;
INFILE 'c:/Users/sharvey8/Desktop/University(1).txt' DLM='09'X DSD FIRSTOBS=2;
INPUT School :$40. State $ Location :$15. GradRate $ Cost $ Acceptance $ Undergrad $;
RUN;
PROC PRINT DATA=University;
RUN;
DATA University;
set University;
IF Acceptance <= 25 THEN Selective='Yes';
ELSE IF Acceptance > 25 THEN Selective='No';
RUN;
PROC PRINT DATA=University;
RUN;
You may need to tweak the informat to read in the percentages correctly but this is likely close to what you need. I would recommend you fix the data at the import stage though, not do a conversion after the fact if possible. It's a cleaner method.
*new data set name on the output;
DATA University_Categorized;
set University;
*convert to numeric;
acceptance_num = input(acceptance, percent12.);
*categorize;
IF acceptance_num <= 0.25 THEN Selective='Yes';
ELSE IF acceptance_num > 0.25 THEN Selective='No';
run;
PROC PRINT DATA=University_Categorized;
RUN;
@sharvey8 wrote:
I am trying to run this code but it won't recognize the percentages so every answer is coming out at Yes for selective.
DATA University;
INFILE 'c:/Users/sharvey8/Desktop/University(1).txt' DLM='09'X DSD FIRSTOBS=2;
INPUT School :$40. State $ Location :$15. GradRate $ Cost $ Acceptance $ Undergrad $;
RUN;
PROC PRINT DATA=University;
RUN;
DATA University;
set University;
IF Acceptance <= 25 THEN Selective='Yes';
ELSE IF Acceptance > 25 THEN Selective='No';
RUN;
PROC PRINT DATA=University;
RUN;
It would have been more helpful if you had included the data. I am assuming there are "%" in the Acceptance variable. Since you are reading it with a "$", it is coming in as a string and this comparison will not work. You need to use a percent informat like
percent5.
So something like this.
DATA University;
INFILE datalines DLM=',' DSD ;
informat Acceptance percent5. cost dollar6.2;
INPUT School :$40. State $ Location :$15. GradRate $ Cost $ Acceptance Undergrad $;
datalines;
MySchool,WA,Seattle,3,$300.23,%15,29
YourSchool,WA,Tacoma,3,$400.23,%20,29
;
RUN;
When I change the percentage informat like this:
DATA University;
INFILE 'c:/Users/sharvey8/Desktop/University(1).txt' DLM='09'X DSD FIRSTOBS=2;
INPUT School :$40. State $ Location :$15. GradRate $ Cost $ Acceptance percent5. Undergrad $;
RUN;
PROC PRINT DATA=University;
RUN;
I get this
What does the data in that field look like?
My log does not have anything weird popping up as an error.
From the data import step? There's no errors there? You just showed the log from the PROC PRINT not the data import step.
And please post it as text, not an image.
@sharvey8 wrote:
My log does not have anything weird popping up as an error.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.