BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Liangck
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

5 REPLIES 5
art297
Opal | Level 21

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;

Liangck
Calcite | Level 5

Hi art,

Thanks, i get what i wanted

Apperciate it.

LiangCk

Ksharp
Super User

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

Peter_C
Rhodochrosite | Level 12

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)(:);

   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

Tom
Super User Tom
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 16089 views
  • 4 likes
  • 5 in conversation