DATA Step, Macro, Functions and more

Format as a macro variable

Accepted Solution Solved
Reply
Contributor exj
Contributor
Posts: 20
Accepted Solution

Format as a macro variable

Hello,

Is it possible to use format (for example best or numx) as a macro variable?

I have conditions (if/else macro) when reading the data in. Macro reads arguments from .csv file with a comma or a dot in place of the decimal point. Depending on that I would like to use a comma or a dot in place of the decimal point in the output depending arguments separators (comma/dot). Any help will be apprecated.

Thx in advance!


Accepted Solutions
Solution
‎06-08-2012 12:29 PM
Regular Contributor
Posts: 227

Re: Format as a macro variable

Please provide the control date set you are using:

"Macro reads arguments from .csv file"

Yes, you can use a format as the value of a macro variable.

%Let format = best;

The issue is whether you add a period to the end of the format:

%Let format = best.;

you can then use the macro variable in a SAS statement:

Var = put(Var,&Format);

Without the dot as suffix you have to use TWO periods after the macro variable reference

1. to end the macro variable reference

2. to add the dot after the format name.

%Let format = best;

Var = put(Var,&Format..);

Ron.Fehd.macro.maven

View solution in original post


All Replies
Solution
‎06-08-2012 12:29 PM
Regular Contributor
Posts: 227

Re: Format as a macro variable

Please provide the control date set you are using:

"Macro reads arguments from .csv file"

Yes, you can use a format as the value of a macro variable.

%Let format = best;

The issue is whether you add a period to the end of the format:

%Let format = best.;

you can then use the macro variable in a SAS statement:

Var = put(Var,&Format);

Without the dot as suffix you have to use TWO periods after the macro variable reference

1. to end the macro variable reference

2. to add the dot after the format name.

%Let format = best;

Var = put(Var,&Format..);

Ron.Fehd.macro.maven

Super User
Super User
Posts: 7,076

Re: Format as a macro variable

Not sure I am understanding the question completely, but it sounds like you are asking how to read your input and determine whether to use a comma or dot in decimal place?   You are reading values from different regions that use different punctuation characters when printing numbers?  For example they might have two and a half written as 2.5 or 2,5 ?

If you just need to determine this for the full file then you could scan the file once as text and make a decision on what to do.  Then either adjust the code or possible the LOCALE option setting.

PROC Star
Posts: 1,760

Re: Format as a macro variable


This should get you started:


data new;
input C $;
N=inputn(C, ifc(index(C,'.'), '32.', 'numx32.'));
put C= N= ;
cards;
224.5
556,4
run;

C=224.5 N=224.5
C=556,4 N=556.4

Contributor exj
Contributor
Posts: 20

Re: Format as a macro variable

Hello,

Thank you all for your answers. I used call symput, for example I created macro variables with

call symput('separator',',');

call symput('printformat','numx15.5'); (format numx/best depends on whether a comma or dot in decimal place).

I use separator as list separator as "&separator" and printformat as &printformat. (without quatation marks) when making the report in the end.

And again, thank you for hints and help!

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 797 views
  • 9 likes
  • 4 in conversation