Hi everyone
I have two questions for my code. The first code keeps showing "Variable RUN not found in data set WORK.SORT1" and the 2nd code keeps showing "file not exist". Please help me with these two codes. Thanks a lot! I attached two files below. REALLY hope someone help me! Thanks again!!!!
Code 1:
data exercise1;
input Patient 1-2 Weight 5-7 Height 9-10 Age 12-13 @15 BMI Smoking $ 26-37 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 heavy smoker 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 heavy smoker 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
proc print data=exercise1;
run;
ods listing close;
ods html body='C:\Users\joann\Desktop\ex1.html';
title1 'Asthma Patients';
title2 'Basic Data Set';
footnote 'Data from Medical Records';
options nonumber nodate;
proc sort data=exercise1 out=sort1;
by Smoking Patient;
proc print data=sort1 noobs;
var Patient Asthma Age BMI;
by Smoking;
format BMI 5.2
run;
ods html close;
ods listing;
Code 2:
proc import out=Exercise2
datafile="C:\Users\joann\Desktop\Exam_Ex2.xls"
dbms=Excel replace;
run;
proc print; run;
title;
option nonumber nodate;
proc report data=Exercise2 nowd headline headskip;
column State_Name State_Abbrev_ Postal_Abbrev_ Area__Sq_Mi_ Population;
define State_Name/width=20 'State Name' left;
define State_Abbrev_/width=7 'State/Abbrev.' left spacing=7 ;
define Postal_Abbrev_/width=7 'Postal/Abbrev.' left spacing=10 ;
define Area__Sq_Mi_/format=comma7.0 width=8 'Area/(Sq Mi)' right spacing=8 ;
define Population/format=comma10. width=10 'Population' right spacing=10 ;
run;
You're missing a semicolon on the format statement. So the RUN looks like part of the format statement and the variable isn't found.
format BMI 5.2;
Here are 2 files needed.
Thanks for helping out again.
It's a bit hard to parse what you've posted.
Can you explain the second error in more detail, or post the new code and log with the error?
In general, you should fix errors in the order they appear.
Here are some errors:
ERROR: Connect: Class not registered
ERROR: Error in the LIBNAME statement
And it also says the file cannot be found. I run this code before it worked, but I had no idead dit stopped running and gave me troubles. here is the code again:
proc import out=Exercise2
datafile="C:\Users\joann\Desktop\Exam_Ex2.xls"
dbms=Excel replace;
run;
proc print; run;
title;
option nonumber nodate;
proc report data=Exercise2 nowd headline headskip;
column State_Name State_Abbrev_ Postal_Abbrev_ Area__Sq_Mi_ Population;
define State_Name/width=20 'State Name' left;
define State_Abbrev_/width=7 'State/Abbrev.' left spacing=7 ;
define Postal_Abbrev_/width=7 'Postal/Abbrev.' left spacing=10 ;
define Area__Sq_Mi_/format=comma7.0 width=8 'Area/(Sq Mi)' right spacing=8 ;
define Population/format=comma10. width=10 'Population' right spacing=10 ;
run;
@wang_ziyi01 wrote:
Here are some errors:
ERROR: Connect: Class not registered
ERROR: Error in the LIBNAME statement
And it also says the file cannot be found. I run this code before it worked, but I had no idead dit stopped running and gave me troubles. here is the code again:
You have an XLS file? If it worked and stopped, what changed in between?
I can't really help with path issues, though it doesn help if you post the full log. The log does include indications of what the solution might be if you're used to reading them.
You're missing a semicolon on the format statement. So the RUN looks like part of the format statement and the variable isn't found.
format BMI 5.2;
OMG! Thanks! I am so stupid!!!! Thanks!!!!!! Do you know the second problem?
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.