BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
user1942
Fluorite | Level 6

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!

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

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

View solution in original post

6 REPLIES 6
SASKiwi
PROC Star

Please post your complete SAS log so we can see exactly what is happening.

Patrick
Opal | Level 21

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;

Capture.JPG

   

ballardw
Super User

@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.

user1942
Fluorite | Level 6

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:

data exercise1;
 input Patient $ Weight $ Height $ Age $ BMI $ Smoking $ Asthma;
cards;
14 167 70 65 23.9593878 never no
9 . 74 64 . never yes
4 165 65 25 27.4544379 occasionally no
2 152 67 60 23.8039652 heavysmoker yes
13 161 70 77 23.0985714 occasionally yes
1 143 64 55 24.5432129 occasionally no
7 148 71 61 20.6395556 occasionally yes
11 281 69 45 41.4919135 heavysmoker yes
5 220 70 58 31.5632653 occasionally no
6 182 64 26 31.2368164 never no
8 190 66 74 30.6634527 occasionally yes
12 . . 39 . occasionally yes
3 190 69 63 28.0550305 never no
15 148 67 53 23.1775451 never yes
10 152 65 61 25.2913609 never yes
;
title 'Smoking = Heavy Smoker';
proc sort data=exercise1;
by smoking;
run;
proc print noobs;
 var Patient Asthma Age BMI;
run;
 
 
Here is my some of the log:
Patient=14 Weight=167 Height=70 Age=65 BMI=23.95938 Smoking=never Asthma=. _ERROR_=1 _N_=1
NOTE: Invalid data for Asthma in line 185 19-21.
185        9 . 74 64 . never yes
Patient=9 Weight=  Height=74 Age=64 BMI=  Smoking=never Asthma=. _ERROR_=1 _N_=2
NOTE: Invalid data for Asthma in line 186 37-38.
186        4 165 65 25 27.4544379 occasionally no
Patient=4 Weight=165 Height=65 Age=25 BMI=27.45443 Smoking=occasion Asthma=. _ERROR_=1 _N_=3
NOTE: Invalid data for Asthma in line 187 36-38.
187        2 152 67 60 23.8039652 heavysmoker yes
Patient=2 Weight=152 Height=67 Age=60 BMI=23.80396 Smoking=heavysmo Asthma=. _ERROR_=1 _N_=4
NOTE: Invalid data for Asthma in line 188 38-40.
188        13 161 70 77 23.0985714 occasionally yes
Patient=13 Weight=161 Height=70 Age=77 BMI=23.09857 Smoking=occasion Asthma=. _ERROR_=1 _N_=5
NOTE: Invalid data for Asthma in line 189 37-38.
189        1 143 64 55 24.5432129 occasionally no
Patient=1 Weight=143 Height=64 Age=55 BMI=24.54321 Smoking=occasion Asthma=. _ERROR_=1 _N_=6
NOTE: Invalid data for Asthma in line 190 37-39.
190        7 148 71 61 20.6395556 occasionally yes
Patient=7 Weight=148 Height=71 Age=61 BMI=20.63955 Smoking=occasion Asthma=. _ERROR_=1 _N_=7
NOTE: Invalid data for Asthma in line 191 37-39.
191        11 281 69 45 41.4919135 heavysmoker yes
Patient=11 Weight=281 Height=69 Age=45 BMI=41.49191 Smoking=heavysmo Asthma=. _ERROR_=1 _N_=8
NOTE: Invalid data for Asthma in line 192 37-38.
192        5 220 70 58 31.5632653 occasionally no
Patient=5 Weight=220 Height=70 Age=58 BMI=31.56326 Smoking=occasion Asthma=. _ERROR_=1 _N_=9
NOTE: Invalid data for Asthma in line 193 30-31.
193        6 182 64 26 31.2368164 never no
Patient=6 Weight=182 Height=64 Age=26 BMI=31.23681 Smoking=never Asthma=. _ERROR_=1 _N_=10
NOTE: Invalid data for Asthma in line 194 37-39.
194        8 190 66 74 30.6634527 occasionally yes
Patient=8 Weight=190 Height=66 Age=74 BMI=30.66345 Smoking=occasion Asthma=. _ERROR_=1 _N_=11
NOTE: Invalid data for Asthma in line 195 26-28.
195        12 . . 39 . occasionally yes
Patient=12 Weight=  Height=  Age=39 BMI=  Smoking=occasion Asthma=. _ERROR_=1 _N_=12
NOTE: Invalid data for Asthma in line 196 30-31.
196        3 190 69 63 28.0550305 never no
Patient=3 Weight=190 Height=69 Age=63 BMI=28.05503 Smoking=never Asthma=. _ERROR_=1 _N_=13
NOTE: Invalid data for Asthma in line 197 31-33.
197        15 148 67 53 23.1775451 never yes
Patient=15 Weight=148 Height=67 Age=53 BMI=23.17754 Smoking=never Asthma=. _ERROR_=1 _N_=14
NOTE: Invalid data for Asthma in line 198 31-33.
198        10 152 65 61 25.2913609 never yes
Patient=10 Weight=152 Height=65 Age=61 BMI=25.29136 Smoking=never Asthma=. _ERROR_=1 _N_=15
NOTE: The data set WORK.EXERCISE1 has 15 observations and 7 variables.
NOTE: DATA statement used (Total process time):
      real time           0.08 seconds
      cpu time            0.06 seconds

199  ;
200  title 'Smoking = Heavy Smoker';
201  proc sort data=exercise1;
202  by smoking;
203  run;
NOTE: There were 15 observations read from the data set WORK.EXERCISE1.
NOTE: The data set WORK.EXERCISE1 has 15 observations and 7 variables.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.04 seconds
      cpu time            0.01 second
 
SASKiwi
PROC Star

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 3575 views
  • 1 like
  • 4 in conversation