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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 2 replies
  • 1327 views
  • 3 likes
  • 3 in conversation