BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tesu
Calcite | Level 5

In my "D:\work\" folder, I have two types of files, that are "8-digit-number_type.dbf" and "character_type.dbf" as follows: 00093282.dbf, 00345602.dbf, 69209340.dbf, 69806980.dbf, 92406482.dbf, 99999999.dbf,... aaa.dbf, bbb.dbf, ...

I want to take only the "8-digit-number_type.dbf" files, and exclude the character type files. (I don't care about the character type files.) Then, I want to create a text file (say, namelist.txt) that contains the list of names of the dbf files as follows:

00093282

00345602

69209340

69806980

99999999

....

How can I do that in SAS?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
MikeZdeb
Rhodochrosite | Level 12

hi ... same idea, use a pipe but with DIR/B...


filename x pipe 'dir/b "z:\*.dbf" ' ;

filename y 'z:\namelist.txt';

data _null_;

infile x dlm='.';

file y;

input name : $20.;

if ^verify(trim(name),'0123456789') then put name;

run;

View solution in original post

6 REPLIES 6
PGStats
Opal | Level 21

Start with this:

filename toto PIPE "DIR ""D:\work\*.dbf"" " console=min;

data _null_;
length name $200;
infile toto firstobs=6 truncover;
input a$ b$ c$ file $char200.;
file "D:\work\namelist.txt";
name = trim(tranwrd(upcase(file),".DBF",""));
if anyalpha(name) = 0 then put name;
run;

PG

PG
tesu
Calcite | Level 5

I run it, and the namelist.txt looks like the following:

35,548 00093282

17,539 00095480

12,406 00095520

38,854 00095602

10,927 00098880

18,670 00099999

29,819 00340240

12,952 00340560

569,260 00345602

198,085 00346162

3,458 00347560

25,072 00349999

18,670 00400040

3,010 00409999

65,737 00801692

...

Some numbers that I don't want in the first column. But I can remove the first column later.

Thank you so much.

PGStats
Opal | Level 21

Take Mike's code, it's much better, mine was just an approximation. - PG

PG
MikeZdeb
Rhodochrosite | Level 12

hi ... same idea, use a pipe but with DIR/B...


filename x pipe 'dir/b "z:\*.dbf" ' ;

filename y 'z:\namelist.txt';

data _null_;

infile x dlm='.';

file y;

input name : $20.;

if ^verify(trim(name),'0123456789') then put name;

run;

tesu
Calcite | Level 5

This code produces the list that I want. Thank you so much.

Ksharp
Super User

If you only want 8 digit file name ,I prefer to Perl Regular Expression.

if prxmatch('/\d{8}/',name) then put name;

Ksharp

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
  • 6 replies
  • 1497 views
  • 0 likes
  • 4 in conversation