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;

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!

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
  • 7 replies
  • 642 views
  • 5 likes
  • 4 in conversation