BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Q1983
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
pradeepalankar
Obsidian | Level 7

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

2 REPLIES 2
Reeza
Super User

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

pradeepalankar
Obsidian | Level 7

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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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