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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Ron_MacroMaven
Lapis Lazuli | Level 10

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

4 REPLIES 4
Ron_MacroMaven
Lapis Lazuli | Level 10

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

Tom
Super User Tom
Super User

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.

ChrisNZ
Tourmaline | Level 20


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

exj
Calcite | Level 5 exj
Calcite | Level 5

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!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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