BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
luis_costa
Calcite | Level 5
I'm trying to read a raw data file with the R$ (brazilian's currency) prefix.
 
What I can do by now is to read as character, use compress() to only keep digits, and then input() with a 10.2 informat and it works fine.
 
But I want a more "elegant" way to read this file, like using a custom informat in input.
 
Is it possible to do something like that?
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

You might be able to use an NLMNLBRLw.d informat.

 

data example;
    x='R$123,456.78';
    y= input(x,NLMNLBRL32.);
run;

There is a corresponding form to display the values in the same form.

View solution in original post

9 REPLIES 9
data_null__
Jade | Level 19

You need the LOCALE system option and an NLS informat.

 

554  data _null_;
555     x = 'R$100,50';
556     y = input(x,NLMNY10.);
557     z = input(x,NLMNY10.2);
558     put (y z)(=NLMNY10.2);
559     put _all_;
560     run;

y=R$100,50 z=R$100,50
x=R$100,50 y=100.5 z=100.5 _ERROR_=0 _N_=1

 

 

novinosrin
Tourmaline | Level 20

My oh my!! Guru @data_null__  How did you know that?

data_null__
Jade | Level 19
I didn't know I had to look it up.
ballardw
Super User

@data_null__ wrote:

You need the LOCALE system option and an NLS informat.

 

554  data _null_;
555     x = 'R$100,50';
556     y = input(x,NLMNY10.);
557     z = input(x,NLMNY10.2);
558     put (y z)(=NLMNY10.2);
559     put _all_;
560     run;

y=R$100,50 z=R$100,50
x=R$100,50 y=100.5 z=100.5 _ERROR_=0 _N_=1

 

 


This was where I started as well. But I remembered that there were some locale specific formats I had encountered (while looking for something else) and thought there might be a Brazil version. So I searched the formats documentation for Brazil an lo and behold, there is one.

ballardw
Super User

You might be able to use an NLMNLBRLw.d informat.

 

data example;
    x='R$123,456.78';
    y= input(x,NLMNLBRL32.);
run;

There is a corresponding form to display the values in the same form.

data_null__
Jade | Level 19

@ballardw wrote:

You might be able to use an NLMNLBRLw.d informat.

 

data example;
    x='R$123,456.78';
    y= input(x,NLMNLBRL32.);
run;

There is a corresponding form to display the values in the same form.


I believe that @ballardw suggestion is best option because you don't have to change the LOCALE.

data_null__
Jade | Level 19

@ballardw wrote:

You might be able to use an NLMNLBRLw.d informat.

 

data example;
    x='R$123,456.78';
    y= input(x,NLMNLBRL32.);
run;

There is a corresponding form to display the values in the same form.


I believe this is the better option because you don't have to fiddle with LOCALE.

novinosrin
Tourmaline | Level 20

Much thanks @ballardw  and @data_null__   . I learned something new. Great stuff!!!

luis_costa
Calcite | Level 5
Thank you so much guys!
 
As @data_null__ said, both @data_null__ and @ballardw answers works perfectly but I will mark @ballardw answer as the solution because we don't have to use the locale option.
 
Thanks again!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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