BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Snaigius
Calcite | Level 5
DATA MYDATA;
INPUT metai ketvirciai kiekis;
DATALINES;
2012 1 4
2012 2 8
2012 3 9
2012 4 12
2013 1 3
2013 2 5
2013 3 10
2013 4 13
;
Data formatas;
Set MYDATA;
eurai = compress(kiekis) ;
vienetai =cats('per'||' '|| substr(eurai,1,2)|| 'eur'); 
Proc print Data=formatas;
VAR Metai Ketvirciai vienetai;
Run;


Hello everyone, how to change number "vienetai" format from 4, 8, 9 ,12.... to 4.00 , 8.00 , 9.00 , 12.00....

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

To apply a format to a number use the PUT() function.  It looks like you need the CATX() not the CATS() function.

data mydata;
  input metai ketvirciai kiekis;
datalines;
2012 1 4
2012 2 8
2012 3 9
2012 4 12
2013 1 3
2013 2 5
2013 3 10
2013 4 13
;
data formatas;
  set mydata;
  length vienetai $20 ;
  vienetai=catx(' ','per',put(kiekis,comma10.2),'eur');
run;
Obs    metai    ketvirciai    kiekis      vienetai

 1      2012         1           4      per 4.00 eur
 2      2012         2           8      per 8.00 eur
 3      2012         3           9      per 9.00 eur
 4      2012         4          12      per 12.00 eur
 5      2013         1           3      per 3.00 eur
 6      2013         2           5      per 5.00 eur
 7      2013         3          10      per 10.00 eur
 8      2013         4          13      per 13.00 eur

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

You wouldn't use CATS to change a number format.

 

You can simply assign a format to the numeric variable, such as

 

format eurai 8.2;

where the .2 indicates you want two digits after the decimal point.

--
Paige Miller
Snaigius
Calcite | Level 5

But i need from both number sides write word's "per .... eur " 

Snaigius
Calcite | Level 5

Screenshot_9.png
I need make like this 

Rick_SAS
SAS Super FREQ

Is this what you are looking for?

 

Data formatas;
Set MYDATA;
length eurai $ 5. vienetai $ 20. ;
eurai = putn(kiekis, "5.2");
vienetai =cats('per'||' '|| eurai || 'eur');
run;
 
Snaigius
Calcite | Level 5
Nope, dont work it. I need "kiekis" in result get "per" 'number' "eur", like a sample above. I send photo
Tom
Super User Tom
Super User

To apply a format to a number use the PUT() function.  It looks like you need the CATX() not the CATS() function.

data mydata;
  input metai ketvirciai kiekis;
datalines;
2012 1 4
2012 2 8
2012 3 9
2012 4 12
2013 1 3
2013 2 5
2013 3 10
2013 4 13
;
data formatas;
  set mydata;
  length vienetai $20 ;
  vienetai=catx(' ','per',put(kiekis,comma10.2),'eur');
run;
Obs    metai    ketvirciai    kiekis      vienetai

 1      2012         1           4      per 4.00 eur
 2      2012         2           8      per 8.00 eur
 3      2012         3           9      per 9.00 eur
 4      2012         4          12      per 12.00 eur
 5      2013         1           3      per 3.00 eur
 6      2013         2           5      per 5.00 eur
 7      2013         3          10      per 10.00 eur
 8      2013         4          13      per 13.00 eur
Snaigius
Calcite | Level 5

Thank you. its works !!

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 576 views
  • 2 likes
  • 4 in conversation