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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: