Hello experts!! I'm new to SAS and programming in general. I still don't understand how to import data tables correctly and I don't know if I'm referencing the data files correctly either. I am using SAS 9.4
Here is the homework problem I am doing:
Import the data file 'Asthma_Ex1.xls' and write the SAS code to obtain the list report stored in file 'outdat_Ex1.html'.
Here is my code:
%web_drop_table(WORK.IMPORT);
FILENAME REFFILE '/Users/016698251/Desktop/STAT475/Asthma_Ex1.xls';
PROC IMPORT DATAFILE=REFFILE DBMS=XLS OUT=WORK.IMPORT;
GETNAMES=YES;
RUN;
proc sort data=WORK.IMPORT out=WORK.out;
by patient;
run;
ODS LISTING CLOSE;
PROC REPORT DATA=WORK.out;
title 'Smoking = Heavy Smoker';
COLUMN Patient Asthma Age BMI;
format BMI $char5.;
where smoking='Heavy Smoker';
RUN;
ODS HTML CLOSE;
ODS LISTING;
ODS LISTING CLOSE;
PROC REPORT DATA=WORK.out;
title 'Smoking = Never';
COLUMNS Patient Asthma Age BMI;
format BMI $char5.;
where smoking='Never';
RUN;
ODS HTML CLOSE;
ODS LISTING;
ODS LISTING CLOSE;
PROC REPORT DATA=WORK.out;
title 'Smoking = Occasionally';
COLUMNS Patient Asthma Age BMI;
format BMI $char5.;
where smoking='Occasionally';
footnote 'Data from Medical Records';
RUN;
ODS HTML CLOSE;
ODS LISTING;
I keep getting no output and a message saying "No observations were selected from data set WORK.OUT" and "No observations in input data set."
I feel like I may be importing the files incorrectly?? I'm not sure what to do.
Thanks!
Try an input statement like this. Your asthma column is character so you need to add the dollar sign to read it as such. Weight, Height, Age should be read as numbers so don't use a dollar sign.
input Patient $ Weight Height Age BMI Smoking $ Asthma $;
t
Please post your complete SAS log so we can see exactly what is happening.
Welcome to the SAS Communities.
Please post the SAS Log as else it's really hard to tell where things are not working for you.
Questions/Remarks:
1. Are there any WARNING or ERROR in your log?
2. Do you have any data in WORK.IMPORT?
3. Why are you sorting by patient if you don't use this sorting in your reports?
4. You could sort by variable smoking and then use this variable in your Proc Report for by group processing. This way you only need a single Proc Report.
Proc Report ....; by smoking; ....
5. Using by group processing allows you to use the #byval and #byvar title options for by group specific titles. Here some sample code:
options nobyline;
title "#byvar1 = #byval1";
proc print data=sashelp.class;
by name;
run;
title;
@user1942 wrote:
I keep getting no output and a message saying "No observations were selected from data set WORK.OUT" and "No observations in input data set."I feel like I may be importing the files incorrectly?? I'm not sure what to do.
Thanks!
"No observations in input data set." means just that, the input data set doesn't have any observations or records. That would likely mean a problem with the results of the Proc Import.
Either read the log carefully for the proc import step or rerun that code and show us the log result. To share the log highlight and copy the lines from the log and on the forum open a code box using the {I} or "running man" icon, then paste. Similar with code.
If the log says anything about no records imported or similar then that needs to be addressed before anything else.
Hello everyone, I decided to manually input the data as my professor said it was too complicated to import. This is what i have now, but it keeps saying that the asthma has invalid data.
this is what my output should look like:
file:///C:/Users/emmy/AppData/Local/Temp/Temp4_homework2%20(1).zip/homework2/outdata_Ex1.html
here is my code:
Try an input statement like this. Your asthma column is character so you need to add the dollar sign to read it as such. Weight, Height, Age should be read as numbers so don't use a dollar sign.
input Patient $ Weight Height Age BMI Smoking $ Asthma $;
t
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.