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
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;
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;
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.
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.