Help using Base SAS procedures

Using Data step generate .csv create header on first line ONLY

Accepted Solution Solved
Reply
Contributor
Posts: 21
Accepted Solution

Using Data step generate .csv create header on first line ONLY

hi all

     i created a datastep to generate a delimited csv file.Code as below:

Sources Code:

         data _null_;

          set etllib._101100_MonthlyDSFACT;

          FILE DelSum DLM=',' notitles header=headrtne;

          PUT  WhsCode :$8.

               DocDate :yymmddn8.

               DocDueDate :yymmddn8.

               ItemCode :$20.

               Quantity ;

        return;

               headrtne:

               PUT @1 'WhsCode,DocDate,DocDueDate,ItemCode,Quantity';

          return;

          run;

Output: DelSum_20111012.csv

WhsCode,DocDate,DocDueDate,ItemCode,Quantity

B09,20110926,20110926,10423632,2

WhsCode,DocDate,DocDueDate,ItemCode,Quantity

B11,20110926,20110926,10421902,1

My Expected Output is like this

WhsCode,DocDate,DocDueDate,ItemCode,Quantity

B09,20110926,20110926,10423632,2

B11,20110926,20110926,10421902,1

How can i do so with the data step.

beside, i tried before using proc export to done the job.its provide me the nice output except the date format is following the sas date format

/*

          proc export data=etllib._101100_MonthlyDSFACT

                    file="F:\abc\&&FileNameD%sysfunc(putn(&&Todaydate,yymmddn8.))&&Extension"

                    dbms=csv

                    Replace;

          run;

*/

Is there other way to deal with it?

Please help.

Thank you:

LiangCk


Accepted Solutions
Solution
‎10-11-2011 11:08 PM
PROC Star
Posts: 7,363

Using Data step generate .csv create header on first line ONLY

Liang,

I think you only need something like:

ata _null_;

  set etllib._101100_MonthlyDSFACT;

  FILE DelSum DLM=',';

  if _n_ eq 1 then

   PUT @1 'WhsCode,DocDate,DocDueDate,ItemCode,Quantity';

  PUT WhsCode :$8.

      DocDate :yymmddn8.

      DocDueDate :yymmddn8.

      ItemCode :$20.

      Quantity ;

run;

View solution in original post


All Replies
Solution
‎10-11-2011 11:08 PM
PROC Star
Posts: 7,363

Using Data step generate .csv create header on first line ONLY

Liang,

I think you only need something like:

ata _null_;

  set etllib._101100_MonthlyDSFACT;

  FILE DelSum DLM=',';

  if _n_ eq 1 then

   PUT @1 'WhsCode,DocDate,DocDueDate,ItemCode,Quantity';

  PUT WhsCode :$8.

      DocDate :yymmddn8.

      DocDueDate :yymmddn8.

      ItemCode :$20.

      Quantity ;

run;

Contributor
Posts: 21

Using Data step generate .csv create header on first line ONLY

Hi art,

Thanks, i get what i wanted

Apperciate it.

LiangCk

Super User
Posts: 9,687

Using Data step generate .csv create header on first line ONLY

How about:

  data _null_;

          set sashelp.class;

          FILE print DLM=',' notitles header=headrtne;

          PUT  names $8.

               weight  ;

        return;

               headrtne :

               PUT @1 'name,weight';

          run;

Ksharp

Valued Guide
Posts: 2,175

Using Data step generate .csv create header on first line ONLY

Ksharp

I like the idea, but it needs that $8. removed or prefixed with :

Attempting to generalise suggested

%let list = age

name       height   weight ;

%let dlm  = %str(,) ;

data _null_;

   set sashelp.class( keep=&list);

   FILE print DLM= "&dlm"  notitles header=headrtne;

   PUT  (&list)(Smiley Happy;

   return;

   headrtne :

      PUT @1 "%sysfunc( translate( %sysfunc( compbl( &list)), %str(&dlm), %str( ) ))" ;

run;

but I'm not sure how well it would work with a tab delimiter

peterC

Super User
Super User
Posts: 6,502

Using Data step generate .csv create header on first line ONLY

You do not what to use HEADER option on the FILE statement to generate a CSV file.

It will only work with the PRINT option but then it will also generate page breaks (formfeeds) and extra header lines.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 6057 views
  • 4 likes
  • 5 in conversation