BookmarkSubscribeRSS Feed
renjithr
Quartz | Level 8

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

6 REPLIES 6
renjithr
Quartz | Level 8

Forgot to mention the above code is in a macro.

ballardw
Super User

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.


Ksharp
Super User

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

NYSPhil
Calcite | Level 5

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


sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 6 replies
  • 5159 views
  • 0 likes
  • 6 in conversation