BookmarkSubscribeRSS Feed
Fluorite | Level 6

Hi all, 


I am working on a college assignment and have imported an excel sheet that I have, which consists of these fields (as per the excel) . Here the discounted price shows as 176.63



However, in SAS it is different for some values - for example the same value is showing as Rs. 177663.00. It has not taken into account the 176.63. 



This is is the code I used - which includes compressing it to remove the rupee sign, changing it from char to num.  I have eventually formatted it to include ruppee sign. 

main code:


data Amazon.Products_mod;
set Amazon.Products_Nodup;

A_Price= input(compress(actual_price, , 'kd'), comma10.);
put "Actual Price (numeric):" A_Price comma10.;
format A_Price currency_fmt.;

D_Price= input(compress(discounted_price, , 'kd'), comma12.);
put "Discounted Price (numeric):" D_Price comma12.;
format D_Price currency_fmt.;

rating_count_cmp = compress(rating_count);
rating_count_new = input(rating_count_cmp, comma12.);

* Dropping irrelevant values or old values that have been converted and replaced;
drop discounted_price rating_count_cmp rating_count img_link product_link actual_price;

* including the INR sign;
proc format;
picture currency_fmt (round)
low-high = '₹' 00000009.00 (prefix='₹');


It works fine with this code, but I need to add in the rupee sign to this. 


Alternate code with the rupee sign included:

data Amazon1.Products_mod;
set Amazon1.Products_Nodup;
actual_price_cmp = compress(actual_price, "₹");
act_price = input(actual_price_cmp, comma15.);

discounted_price_cmp = compress(discounted_price, "₹");
disc_price= input(discounted_price_cmp, comma15.);

rating_count_cmp = compress (rating_count);
rating_count_new = input(rating_count_cmp, comma12.);
format disc_price currency
drop actual_price discounted_price actual_price_cmp discounted_price_cmp rating_count_cmp rating_count
img_link product_link;

Any urgent suggestion on what can be done here and how i can get the right number + a comma for ease of readability. 

Super User

Your compress is using the option 'kd' which means "keep the characters in the list" (k) and "add digits to the list" (d). Which means that DECIMAL points are not kept.

You can see that in this example:

data example;
   y= compress(x,,'kd');

You compress should keep the decimal:

A_Price= input(compress(actual_price,'.' , 'kd'), comma10.);

Place commas in Picture value where you expect them to appear. Remember that you need to consider additional characters to display the same range of values.

proc format;
picture currency_fmt (round)
low-high = '00,000,009.00' (prefix='₹');

I am not sure what encoding may be needed to get that character to appear correctly though.

Fluorite | Level 6

Oh My God! Thank you so much! This worked perfectly. Is there any way I can also add in a comma to these numbers? 

Super User

@kk131 wrote:

Oh My God! Thank you so much! This worked perfectly. Is there any way I can also add in a comma to these numbers? 

Did you try the suggested alternate format? I might expect the currency symbol to not display depending on session encoding but I do expect that the commas would appear.



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 2 in conversation