BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JohnT
Quartz | Level 8

Gday,

I'm not sure if I really need to save a format as text however, it's the only solution I can think of right now.  I just don't know how to do it.

I want the following table (it will only ever have four lines):

IncomeSuccess
Jan-12     831.59 1.751%
Jan-11     923.87 1.759%
Change11.10%0.47%

^^

The first two records is in my data.  The third record is the percentage difference between the above two records (Success and Income are both formatted numbers) .  I can do that, however I want to maintain the formats.

Obviously the percentage difference will be fine for Success (although the number of decimal places would be quite right, I could probably live with it) but what about Income?  This is why I think I need to convert these values into text.

How would I do that?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You can use the PUT function.  For example in a data step.

data want ;

  set have ;

  if col1='Change' then incometext = put(income,percent.);

  else incomtext=put(income,8.2);

run;

View solution in original post

4 REPLIES 4
Sudhakar_A
Calcite | Level 5

It will be good if you use the numeric variable for calculation purpose and for reporting you can use the Character with unique formats

Tom
Super User Tom
Super User

You can use the PUT function.  For example in a data step.

data want ;

  set have ;

  if col1='Change' then incometext = put(income,percent.);

  else incomtext=put(income,8.2);

run;

JohnT
Quartz | Level 8

Thanks Tom,

I think I had a brain snap yesterday.

Worked perfectly as described.

Ksharp
Super User

If you can sure the value of income could not be between 0 and 1, then you can use embed format.

But I still recommend you to use the method Tom proposed.

data want;
input Income     Success percent8.;
format success percent8.2;
cards;
831.59      1.751%
923.87      1.759%
.1110     0.47%
;
run;
proc format;
value x
 0-1=[percent8.2]
 ;
run;
data want;
 set want;
 format income x.;
run;


Ksharp

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 700 views
  • 0 likes
  • 4 in conversation