BookmarkSubscribeRSS Feed
Anita_n
Pyrite | Level 9

Hello,

I have defined a proc format  and a macro which looks for example like below. I want myfolder  on my gpath to be replaced with the defined formats. For example format &myfolder  $folder.;

 

proc format library = ft;
value $folder
        'foldernameA'= 'foldername A containing books'
        'foldernameB'= 'foldernameB containing pencils'
;
run;



%macro gdesign (myfie, myfolder);

***********some sas codes*****************; ods listing gpath= "C:\graphs\&myfolder "; ***********some sas codes*****************; %mend gdesign;

%gdesign(folder1,foldernameA);
%gdesign(folder1, foldernameB);

If I place this on the gpath ( like this:

ods listing gpath= "C:\graphs\format &myfolder $folder. ";

) I get an error

 

Is there any way to do that?

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

That is not really the place for formats, formats are applied to Data in Datasets.  You could fool it by using combinations of sysfunc and functins, but there really is no need.  You would use macro to do this kind of find/replace e.g (and you need to supply a concrete example of input/output for exact code):

%gdesign(folder1,foldername A containing books);
%gdesign(folder1,foldername B containing pencils);
Anita_n
Pyrite | Level 9

Thanks this worked fine. The only problem I still have is that . I need to use this in many macros,  that means I have to type in this long name always. I wish to store this in a variable so that if I call the variable it outputs foldername A contain books

 

Is there any way out

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, instead of having it as a parameter, just put at the top of your program:

%let fname=folder with pencils;

And then use &fname. throughout your other code, to change it, just change that one line.

Anita_n
Pyrite | Level 9

Thanks a lot for that

sas-innovate-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

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
  • 613 views
  • 0 likes
  • 2 in conversation