DATA Step, Macro, Functions and more

Displaying count in a proc export statement

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 131
Accepted Solution

Displaying count in a proc export statement

Proc sql;

Create table test as

Select ln, region

Case when ln ne ‘’ then count(ln) else 0 end as cnt

Quit;

Sample output

Ln           region                   cnt

11           west                      4

12           east                       4

13           north                       4

15           south                    4

data _null_;

File "/server/file_&cnt..txt"   (file__4..txt would be the exported output)

lrecl=30000 dsd dlm='|' termstr=crlf  ;

run;

However I do not want to display the header cnt.  I want output like this

11|west|

12|east|

The reason I chose to address the cnt in the proc statement is because I am not sure if there is a way to do a macro to count the

Number of recrods and then use it in the proc export statement


Accepted Solutions
Solution
‎04-10-2015 12:06 AM
Frequent Contributor
Posts: 106

Re: Displaying count in a proc export statement

if you just want to put count of rows in the file name not split it on some variable then you may use this:

data source_table;

input Ln region :$5.;

cards;

11 west

12 east

13 north

15 south

;

proc sql;select count(ln) into :cnt from source_table;quit;

data _null_;

File "Serverpath\file__%TRIM(&cnt.).txt" lrecl=30000 dsd dlm='|' termstr=crlf ;

set source_table;

put LN region;

run;

View solution in original post


All Replies
Super User
Posts: 17,724

Re: Displaying count in a proc export statement

If you have the CNT as a variable in your dataset you can use the FILEVAR option to name the file instead.

Solution
‎04-10-2015 12:06 AM
Frequent Contributor
Posts: 106

Re: Displaying count in a proc export statement

if you just want to put count of rows in the file name not split it on some variable then you may use this:

data source_table;

input Ln region :$5.;

cards;

11 west

12 east

13 north

15 south

;

proc sql;select count(ln) into :cnt from source_table;quit;

data _null_;

File "Serverpath\file__%TRIM(&cnt.).txt" lrecl=30000 dsd dlm='|' termstr=crlf ;

set source_table;

put LN region;

run;

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 204 views
  • 3 likes
  • 3 in conversation