BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASdevAnneMarie
Barite | Level 11
If I have a numeric variable with the value 1500 and want to turn it into a character variable, with the space in this way 1 500 €. Can you please tell me how I can edit my expression to resolve this?
 
New_value=compress(put(Value), euro10.2));
 
I mean, when I use the compress function, there is no space any more...
 
Thank you for your help !
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Or just use the appropriate LOCALE setting then you can use the NLMNY format.

92    %let locale=%sysfunc(getoption(locale));
93    %put &=locale;
LOCALE=EN_US
94    options locale='fi_FI';
95    data test;
96      Montant_min_de_vers_init=1500;
97      test=left(put(Montant_min_de_vers_init,euro10.));
98      test1=substr(cats(test,char(test,1)),2);
99      test2=translate(test1,' ',',');
100     test3=put(1500,nlmny10.);
101     put (test:) (=:$quote. /);
102   run;

test="€1,500"
test1="1,500€"
test2="1 500€"
test3="   1 500 €"
NOTE: The data set WORK.TEST has 1 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


103   options locale="&locale";

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

Why do a COMPRESS if you don't want the result of COMPRESS?

 

As far as I know, there is no built in money format that uses a space instead of a comma or a period. Why not use a function that replaces the comma with a space? The TRANSLATE function will do that for you.

--
Paige Miller
SASdevAnneMarie
Barite | Level 11

Thank you, but unfortunately it doesn't work :

 

data test;
set ACCORD;
test=compress(put(Montant_min_de_vers_init,euro10.));
test1=compress(substr(test,2))||"€";

test2=translate(test1,',',' ');
keep test test1 test2;
run;

 

MarieT_0-1645200255629.png

 

PaigeMiller
Diamond | Level 26

You have typed the arguments to the TRANSLATE function incorrectly. If you want to replace a comma with a space, you would use this

 

test2=translate(test1,' ',',');
--
Paige Miller
Tom
Super User Tom
Super User

Not sure why you have the COMPRESS() function at all.  You have the arguments to TRANSLATE() backwards.

43    data test;
44      Montant_min_de_vers_init=1500;
45      test=put(Montant_min_de_vers_init,euro10.-L);
46      test1=cats(substr(test,2),char(test,1));
47      test2=translate(test1,' ',',');
48      put (test:) (=:$quote. /);
49    run;

test="€1,500"
test1="1,500€"
test2="1 500€"
Tom
Super User Tom
Super User

Or just use the appropriate LOCALE setting then you can use the NLMNY format.

92    %let locale=%sysfunc(getoption(locale));
93    %put &=locale;
LOCALE=EN_US
94    options locale='fi_FI';
95    data test;
96      Montant_min_de_vers_init=1500;
97      test=left(put(Montant_min_de_vers_init,euro10.));
98      test1=substr(cats(test,char(test,1)),2);
99      test2=translate(test1,' ',',');
100     test3=put(1500,nlmny10.);
101     put (test:) (=:$quote. /);
102   run;

test="€1,500"
test1="1,500€"
test2="1 500€"
test3="   1 500 €"
NOTE: The data set WORK.TEST has 1 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


103   options locale="&locale";
SASdevAnneMarie
Barite | Level 11
Thank you, Tom, it works !
Ksharp
Super User
proc format;
picture fmt
low-high='000 000 000€';
run;

data have;
input x;
want=put(x,fmt. -l);
cards;
1500
12345678
;
run;
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
  • 7 replies
  • 2212 views
  • 5 likes
  • 4 in conversation