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

Hi all!

As the title says, I'm looking for a way to take the name of a column and put it into each field of this column as content.
There are more than 600 data sets where this has to be done so doing it manually is not an option.

Maybe I describe the problem a little more in detail:

- I have 600 csv's

- I 'infile' them with a makro

- each of the corresponding 600 data sets has a title like ' _lib.list_openings_number1_number2'    [for example ' _lib.list_openings_5016_5249434' ]

- I need these numbers as a content of a column named (for example) Origin     (Later, I will have to merge all of the 600 sets so I need a column that makes it possible to tell for each set where it comes from.)

- I tried it with

Origin = scan(&&dat&i ,2 ,'_');

(where dat&i= %scan(&dat,&i,%str( ));

and dat = openings_1372_4975528 openings_1372_4979553 ......(600 csv's) ...openings_5016_5249434 )

(More code's attached)


But this gives me two columns, one named Origin with no filling at all, and one named openings_5016_5249434 with only . as a content in each field. Why?

So both, telling me how to take a title and put in into each field of the column, or telling me how to create 'Origin' correctly in the first place, will solve my problem.

I'd be really happy if somebody could help me Smiley Happy

Thanks
Marina

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20

I'm not really sure on what is your problem.

What happens if you fix the syntax?

But on the other hand, it seems cumbersome to list all files you want to import in the macro call.

If you can assume that all file in a certain directory should be imported, get a directory listing into a SAS table (you could use filename pipe with dir/ls).

Then loop through the table and do call execute the macro using the filename as a parameter. I guess that would make the macro coding easier - no need for %do %while %scan...stuff...?

Data never sleeps

View solution in original post

4 REPLIES 4
LinusH
Tourmaline | Level 20

For starters, you are using the data step function scan (opposed to the corresponding macro function), some you have to either have a column name, or a char constant as first argument, not just unquoted plain text.

Data never sleeps
Marian_2127
Calcite | Level 5

Ok, I see that this makes sense. However, I still don't know how to solve my problem. Any ideas?

Thanks!

LinusH
Tourmaline | Level 20

I'm not really sure on what is your problem.

What happens if you fix the syntax?

But on the other hand, it seems cumbersome to list all files you want to import in the macro call.

If you can assume that all file in a certain directory should be imported, get a directory listing into a SAS table (you could use filename pipe with dir/ls).

Then loop through the table and do call execute the macro using the filename as a parameter. I guess that would make the macro coding easier - no need for %do %while %scan...stuff...?

Data never sleeps
Marian_2127
Calcite | Level 5

Hi, thank you so much!

I was obviously just a little confused about macro/non-macro.

It's working fine now :smileygrin:


(Thanks for the hint about reading everything in the folder instead of listing the names - I will definitely try that, too.)

Thanks!

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
  • 4 replies
  • 903 views
  • 1 like
  • 2 in conversation