DATA Step, Macro, Functions and more

Outputing the Headings for each column

Reply
N/A
Posts: 0

Outputing the Headings for each column

Hi All

How do we output a heading for each column in the data - I am using MVS on the mainframe with SAS - I can write out the data, but need to be heading labels for each of the columns.

Regards
Shelton.
SAS Super FREQ
Posts: 8,868

Re: Outputing the Headings for each column

Posted in reply to deleted_user
Hi:
Not sure what you mean. Are you using PROC PRINT, PROC REPORT, DATA _NULL_? Are you sending output to the LISTING destination (in a mainframe job, this would be the equivalent of the SYSOUT DD location)? How are you "writing out the data"?

Can you post an example of your code?? Refer to this posting for more information about how to post code and maintain the indentation of the code.
http://support.sas.com/forums/thread.jspa?messageID=27609毙

cynthia
N/A
Posts: 0

Re: Outputing the Headings for each column

Posted in reply to deleted_user
Basically what I want to do is output the data to a dataset but also have the field labels appear at the top of the output - like

PartNo Description Price
XXXX somepartx $110.00
YYY someparty $55.00


etc etc
This is what my code looks like now:

[pre]DATA PUTOUT;
SET STOCK;
FILE OUTF1;
PUT @1 PART $12.
@13 DESC $10.
@40 PRICE 8.2;
[/pre]
Super Contributor
Super Contributor
Posts: 3,174

Re: Outputing the Headings for each column

Posted in reply to deleted_user
Given your coded approach, you will need to add a single-line PUT statement to generate a HEADER row. Your DATA step code needs to test for IF _N_=1 and issue a PUT with a text-character row surrounded with double-quotes and commas, most likely. Here's an example:

IF _N_=1 THEN PUT '"VAR1","VAR2","VAR3"';

Of course you may also want to consider the "ODS CSV" approach and use PROC PRINT.

Suggest you search the SAS support http://support.sas.com/ website for ODS CSV examples if that's your alternate approach.


Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Outputing the Headings for each column

Hi Scott

Thanks for the reply - it worked! I didnt want to use ODS as I have used that previously to create a HTML output file. I thought there was an easier way to do this.

This is my code:

DATA PUTOUT;
SET STOCK;
FILE OUTF1;
IF _N_=1 THEN PUT
@01 "PARTNO"
@13 "MONTHIND"
@40 "YEARIND"
;
PUT @1 PART $12.
@13 MONTHIND $1.
@40 YEARIND $1.;

Thanks again.
Shelton.
Respected Advisor
Posts: 3,799

Re: Outputing the Headings for each column

Posted in reply to deleted_user
There are ways to print the names without knowing the names. Another method might use CALL VNEXT.

[pre]
396 data _null_;
397 file log dsd;
398 if _n_ eq 1 then do;
399 if 0 then set sashelp.shoes;
400 put (_all_) (=) @;
401 _file_ = compress(tranwrd(_file_,'=',','),' .');
402 _file_ = substr(_file_,1,length(_file_)-1);
403 put;
404 end;
405 set sashelp.shoes(obs=30);
406 put (_all_)(Smiley Happy;
407 run;

Region,Product,Subsidiary,Stores,Sales,Inventory,Returns
Africa,Boot,Addis Ababa,12,"$29,761","$191,821",$769
Africa,Men's Casual,Addis Ababa,4,"$67,242","$118,036","$2,284"
Africa,Men's Dress,Addis Ababa,7,"$76,793","$136,273","$2,433"
Africa,Sandal,Addis Ababa,10,"$62,819","$204,284","$1,861"
Africa,Slipper,Addis Ababa,14,"$68,641","$279,795","$1,771"
Africa,Sport Shoe,Addis Ababa,4,"$1,690","$16,634",$79
Africa,Women's Casual,Addis Ababa,2,"$51,541","$98,641",$940
Africa,Women's Dress,Addis Ababa,12,"$108,942","$311,017","$3,233"
Africa,Boot,Algiers,21,"$21,297","$73,737",$710
Africa,Men's Casual,Algiers,4,"$63,206","$100,982","$2,221"
[/pre]
Ask a Question
Discussion stats
  • 5 replies
  • 160 views
  • 0 likes
  • 4 in conversation