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
Forgot to mention the above code is in a macro.
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.
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
Hi,
Can you use the %ds2csv macro? It puts out the column headings by default:
Regards,
Amir.
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
You can just use a data step. See this thread:
https://communities.sas.com/message/116724#116724
Or on SAS-L
http://listserv.uga.edu/cgi-bin/wa?A2=ind1202C&L=sas-l&D=0&F=P&P=11485&F=
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.