DATA Step, Macro, Functions and more

How to put title as content into column

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

How to put title as content into column

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

Attachment

Accepted Solutions
Solution
‎03-15-2013 08:54 AM
Super User
Posts: 5,438

Re: How to put title as content into column

Posted in reply to Marian_2127

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


All Replies
Super User
Posts: 5,438

Re: How to put title as content into column

Posted in reply to Marian_2127

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
Occasional Contributor
Posts: 9

Re: How to put title as content into column

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

Thanks!

Solution
‎03-15-2013 08:54 AM
Super User
Posts: 5,438

Re: How to put title as content into column

Posted in reply to Marian_2127

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
Occasional Contributor
Posts: 9

Re: How to put title as content into column

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!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 218 views
  • 1 like
  • 2 in conversation