BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8
ods html file="testsas2.xls";

data lemon;
  input up down sub_product $;
datalines;
2   5    apple
3   2    lemon

data apple;
set lemon;
len_up=up+2;
len_down=down+2;
run;

data check_apple;
set apple;
len_up_up=len_up+2;
len_down_down=len_down+2;
run;

proc means data=check_apple n nmiss max min;
var up down len_up len_down len_up_up len_down_down;
output out = result;
run;

proc print data=result;
run;
ods html close;

May I know what is going to be in the xls file created, I tried but cannot see any result from those data or proc stat in between two ods statements. I was told we are trying to create a html file but save as excel file name. this looks like bad practice, right... 

 

7 REPLIES 7
SASKiwi
PROC Star

Correct. If you are creating an Excel spreadsheet ODS EXCEL is the right output type.

Reeza
Super User

Yes, this is bad practice. Who ever is teaching you used SAS a decade ago or more and hasn't updated their techniques.

Even if it does work, I think Excel won't open that file correctly anymore and who still uses xls files?

I would HIGHLY suggest taking the FREE SAS e-courses instead/on top of whatever else you're doing. 

 

The 2 days on that course will probably be better in the long run. 

 

ods excel file="testsas2.xlsx";

data lemon;
  input up down sub_product $;
datalines;
2   5    apple
3   2    lemon

data apple;
set lemon;
len_up=up+2;
len_down=down+2;
run;

data check_apple;
set apple;
len_up_up=len_up+2;
len_down_down=len_down+2;
run;

proc means data=check_apple n nmiss max min;
var up down len_up len_down len_up_up len_down_down;
output out = result;
run;

proc print data=result;
run;

ods excel close;

@HeatherNewton wrote:
ods html file="testsas2.xls";

data lemon;
  input up down sub_product $;
datalines;
2   5    apple
3   2    lemon

data apple;
set lemon;
len_up=up+2;
len_down=down+2;
run;

data check_apple;
set apple;
len_up_up=len_up+2;
len_down_down=len_down+2;
run;

proc means data=check_apple n nmiss max min;
var up down len_up len_down len_up_up len_down_down;
output out = result;
run;

proc print data=result;
run;
ods html close;

May I know what is going to be in the xls file created, I tried but cannot see any result from those data or proc stat in between two ods statements. I was told we are trying to create a html file but save as excel file name. this looks like bad practice, right... 

 


 

HeatherNewton
Quartz | Level 8

can you confirm if the steps between the two ods line are gonna run nornmally as ususal SAS steps.. and what is gonna be output in the excel file created? all the dataset behind the word data?

HeatherNewton
Quartz | Level 8

what is the correct statement to output the data to an excel file?

ballardw
Super User

@HeatherNewton wrote:

what is the correct statement to output the data to an excel file?


 

Depends on what you mean by "output the data".

 

If you have the SAS license for Access to PC File Formats it would be ODS EXCEL most likely for procedures such as Proc Print.

 

For only data then LIBNAME EXCEL.

Reeza
Super User

@HeatherNewton wrote:

can you confirm if the steps between the two ods line are gonna run nornmally as ususal SAS steps.. and what is gonna be output in the excel file created? all the dataset behind the word data?


Run the code and test it. 

Kurt_Bremser
Super User

Your code does not create an Excel file, but a HTML page file with a wrong extension. This is at best bad practice.

If you want to have an Excel file, use ODS EXCEL and the .xlsx extension (because that is what ODS EXCEL creates).

The ODS destination will receive all print output. What you see in your Output tab in SAS Studio or Enterprise Guide is also what you get in the ODS destination

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 7 replies
  • 1081 views
  • 0 likes
  • 5 in conversation