BookmarkSubscribeRSS Feed
kk131
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

kk131_0-1684478340922.png

 

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. 

kk131_1-1684478340917.png

 

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;
run;

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

 

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;
run;


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

3 REPLIES 3
ballardw
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;
   x='123.45';
   y= compress(x,,'kd');
run;

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='₹');
run;

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

kk131
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? 

ballardw
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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 557 views
  • 0 likes
  • 2 in conversation