Can someone please let me know how can I use Indian currency symbol in SAS program?
Like we do for dollar as below
format Salary :dollar8.;
A similar format can be built like this:
%let inr=%sysfunc(unicode(\u20B9));
proc format;
picture rupee
low - <0 = '00,000,000,000,009.99)' (prefix="(&inr")
0 - high = '00,000,000,000,009.99 ' (prefix="&inr")
;
run;
Which, applied as follows:
data test;
format x rupee.;
x=34341.12; output;
x=-12343452435.44;output;
x=0; output;
run;
Gives:
Related
I nedd to write a PROC FORMAT and PROC FCMPin my SAS programm to convert values in horsepower to watts. Watts should have the following format: XXXXX,XX Watt.
proc fcmp outlib=work.functions.fun;
function hptow(c) $;
n = cats(c*745.7, ' Watts');
return (n);
endsub;
run;
options cmplib=work.functions;
proc format;
value hptow other=[hptow()];
run;
data my_cars;
set sashelp.cars;
format horsepower hptow.;
run;
But results look something like that:
197610.
201339W
How do i change this mistake and have needed output format for formated column?
Set a LENGTH for the variable you are calculating in the function. If you want the space in front of the W then don't remove it by using the CATS() function.
length n $14;
n = put(c*745.7,commax8.2) || ' Watts' ;
Set a default width for the format.
value hptow (default=14) other=[hptow()];
But why not just use a PICTURE format?
proc format ;
picture hptow
low-high = '00009,99 Watt' (mult=74570)
;
run;
Results:
410 data test;
411 do hp=1,2,5,12 ;
412 w=hp*745.7 ;
413 put hp= w= #20 hp hptow.;
414 end;
415 run;
hp=1 w=745.7 745,70 Watt
hp=2 w=1491.4 1491,40 Watt
hp=5 w=3728.5 3728,50 Watt
hp=12 w=8948.4 8948,40 Watt
I have the numeric values of salaries of different employee's. I want to break the ranges up into categories. However I do not want a new column rather, I want to just format the existing salary column into this range method:
At least $20,000 but less than $100,000 -
At least $100,000 and up to $500,000 - >$100,000
Missing - Missing salary
Any other value - Invalid salary
I've done something similar with gender. I just want to use the proc print and format command to show salary and gender.
DATA Work.nonsales2;
SET Work.nonsales;
RUN;
PROC FORMAT;
VALUE $Gender
'M'='Male'
'F'='Female'
'O'='Other'
other='Invalid Code';
PROC FORMAT;
VALUE salrange
'At least $20,000 but less than $100,000 '=<$100,000
other='Invalid Code';
PROC PRINT;
title 'Salary and Gender';
title2 'for Non-Sales Employees';
format gender $gender.;
RUN;
Proc Format is the correct method and you need a numeric format:
proc format;
value salfmt
20000 - <100000 = "At least $20,000 but less than $100,000"
100000 - 500000 = "100,000 +"
. = 'Missing'
other = 'Other';
Then in your print apply the format, similar to what you did for gender.
format salary salfmt.;
This should help get you started.
I created a little function that mimics the R cut functions :
options cmplib=work.functions;
proc fcmp outlib=work.functions.test;
function cut2string(var, cutoffs[*], values[*] $) $;
if var <cutoffs[1] then return (values[1]);
if var >=cutoffs[dim(cutoffs)] then return (values[dim(values)]);
do i=1 to dim(cutoffs);
if var >=cutoffs[i] & var <cutoffs[i+1] then return (values[i+1]);
end;
return ("Error, this shouldn't ever happen");
endsub;
run;
Then you can use it like this :
data Work.nonsales2;
set Work.nonsales;
array cutoffs[3] _temporary_ (20000 100000 500000);
array valuesString[4] $10 _temporary_ ("<20k " "20k-100k" "100k-500k" ">500k");
salary_string = cut2string(salary ,cutoffs,valuesString);
run;
I have a proc report that groups and does subtotals. If I only have one observation in the group, the subtotal is useless. I'd like to either not do the subtotal for that line or not do the observation there. I don't want to go with a line statement, due to inconsistent formatting\style.
Here's some sample data. In the report the Tiki (my cat) line should only have one line, either the obs from the data or the subtotal...
data tiki1;
name='Tiki';
sex='C';
age=10;
height=6;
weight=9.5;
run;
data test;
set sashelp.class tiki1;
run;
It looks like you are trying do something that proc report cannot achieve in one pass. If however you just want the output you describe here is an approach that does not use proc report.
proc sort data = test;
by sex;
run;
data want;
length sex $10.;
set test end = eof;
by sex;
_tot + weight;
if first.sex then _stot = 0;
_stot + weight;
output;
if last.sex and not first.sex then do;
Name = "";
sex = "Subtotal " || trim(sex);
weight = _stot;
output;
end;
keep sex name weight;
if eof then do;
Name = "";
sex = "Total";
weight = _tot;
output;
end;
run;
proc print data = want noobs;
run;
This method manually creates subtotals and a total in the dataset by taking rolling sums. If you wanted do fancy formatting you could pass this data through proc report rather than proc print, Joe gives an example here.
I have this code where I create a proc format statement for dates based on todays date.
Any date prior to today is red and any date in the future is green. However this is a proc report I am calling this statement in and there are blank values for date in some cases. Therefore, I want fields that don't contain a date to be white.
data _null_;
sdate = date ();
format sdate date9.;
call symput('sdate',sdate);
run;
proc format;
value closefmt
low - &sdate ='red'
' ' = 'white'
&sdate - high = 'green';
run;
It doesn't like ' ' = white and doesn't accept null.
Any help would be appreciated.
Thanks in advance.
Use single dot for missing values in numeric variable:
proc format;
value closefmt
low - &sdate ='red'
. = 'white'
&sdate - high = 'green';
run;
/* test code */
data indata;
d = .; output;
do i=-3 to 3;
d = today()+i;
output;
end;
run;
data _null_;
set indata;
format d yymmdds10.;
length color $10;
color = put(d, closefmt. - L);
putlog d color;
run;
data a;
input accountno name $;
datalines;
1.01 x
0.999 harshit
1.99 y
2 kumar
3 manali
;
Run;
proc print; run;
proc format;
value h
0-1='g.0-1'
1-3='g.1-3'
;
run;
proc print data = a;
format accountno h.;
run;
proc summary data = a nway;
class accountno;
format accountno h.;
var accountno;
output out = hpd;
run;
proc print; run;
in proc summary it will not take var accountno also gives
WARNING: Variable accountno already exists on file WORK.HPD.
WARNING: The duplicate variables will not be included in the output data set of the output statement number 1.
so what is the solution?
Not completely sure what you are wanting to get in the output, but I can tell you why you are getting the warning message.
In proc summary, you are using the same variable name in the class statement as you are using in your var statement. In the referent output dataset, the procedure is letting you know that you are duplicating a variable name.
You could add an extra variable in the data step that writes out to data 'a';
If you are trying to just get frequencies of the class variable, remove the var statement completely as in:
proc summary data = a;
class accountvar;
output out = freqs;
run;