Help using Base SAS procedures

How to create .csv sas dataset on mainframe with column headings?

Reply
Frequent Contributor
Posts: 122

How to create .csv sas dataset on mainframe with column headings?

Hi,

I am trying to create a .csv sas dataset on mainframe with column headings.

DATA _NULL_;

  SET DATAOT1.NRI;

  IF MCA = "&MCA1" THEN DO;

  CALL SYMPUT('TEXT_FLG', 'Y');

   FILE &FNME1  DSD DLM=',' LRECL=8000 TITLES;

   IF _N_ EQ 1 THEN

   PUT @1 'MCA,MN1,ADMDT,DISDT,ADMTYPE_NM,ADMSRC_NM,DISP_NM,AGE,

       ED_IND,PAT_ENC_CSN_ID,MDC,SCHED,EXPIRED,BASECLASS,SEX,

       LOS,V_ALL_BARI,CANCER,BMI35,HSP_ACCOUNT_ID,

       ADT_PATIENT_STAT_C,PAT_CLASS,INP_ADM_DT';

   PUT MCA MRN1 ADMDT DISDT ADMTYPE_NM ADMSRC_NM DISP_NM AGE

       ED_IND PAT_ENC_CSN_ID MDC SCHED EXPIRED BASECLASS SEX

       LOS V_ALL_BARI CANCER BMI35 HSP_ACCOUNT_ID

       ADT_PATIENT_STAT_C PAT_CLASS  INP_ADM_DT

       ;

end;

run;

but this code is not writing the column headings.Also in the sas log I see the note that the quouted string(put @1) exceeded 256 characters.

Please share your thoughts.

Thanks

Frequent Contributor
Posts: 122

Re: How to create .csv sas dataset on mainframe with column headings?

Forgot to mention the above code is in a macro.

Super User
Posts: 10,538

Re: How to create .csv sas dataset on mainframe with column headings?

I think the culprit might be the

IF MCA = "&MCA1" THEN DO;

If this condition is not true for the very first record you won't get your headings.

It looks like you are trying to only export the records where this value holds true. If that is so instead of the If statement use a where clause on the set statement to subset the data.

SET DATAOT1.NRI (where =( MCA = "&MCA1" ));

and remove the IF THEN DO; and END; statements.


Super User
Posts: 9,687

Re: How to create .csv sas dataset on mainframe with column headings?

How about using proc export ?

proc export data=sashelp.class(where=(sex='F')) dbms=csv outfile='c:\x.csv' replace;

putnames=yes;

run;

OR

ods _all_ close;

ods csv file='c:\x.csv' ;

proc print data=sashelp.class(where=(sex='F')) noobs;

run;

ods csv close;

ods listing;

Ksharp

Super Contributor
Posts: 282

Re: How to create .csv sas dataset on mainframe with column headings?

Hi,

Can you use the %ds2csv macro? It puts out the column headings by default:

http://support.sas.com/documentation/cdl/en/lebaseutilref/63492/HTML/default/viewer.htm#n0yo3bszlrh0...

Regards,

Amir.

New Contributor
Posts: 3

Re: How to create .csv sas dataset on mainframe with column headings?

What I use when creating a CSV file on the mainframe is ODS CSVALL.  I use with a formatted output proc like PROC PRINT.  Example:

ODS CSVALL FILE = CSVFILE RS=NONE;

PROC PRINT DATA=PRTDATA NOOBS LABEL SPLIT='*';

VAR DATA1 DATA2 ETC.

ODS CSVALL CLOSE;

Don't know how it would work with DATA _NULL_ output


Super User
Super User
Posts: 6,502

Re: How to create .csv sas dataset on mainframe with column headings?

Ask a Question
Discussion stats
  • 6 replies
  • 2137 views
  • 0 likes
  • 6 in conversation