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;
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.
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.
Oh My God! Thank you so much! This worked perfectly. Is there any way I can also add in a comma to these numbers?
@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 now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.