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!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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