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-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
  • 3309 views
  • 9 likes
  • 4 in conversation