Hello All,
I have a input record such as 825,563.25
How do I read it in SAS as a variable which will only show - 82556325
Please could you provide me with the easiest solution ASAP!
Thanks,
Sayan
DATA T_DETAIL;
LENGTH T_DETAIL_COST :$10.
;
INFILE TDETAIL DSD MISSOVER ;
INPUT @1 T_DETAIL_COST
TARGET_STRING = TRANSLATE((T_DETAIL_COST,('','ëï'))) ;
;
PUT @4 ' T_DETAIL COST=' T_DETAIL_COST;
PUT @4 ' T_DETAIL COST=' NEWSTRING;
I tried this but all in vain
@GPNaveen: bad programming practice:
24 data test; 25 input price comma10.2; 26 price2=compress(price,,'kd'); 27 datalines; NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 26:17 NOTE: The data set WORK.TEST has 1 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.02 seconds cpu time 0.00 seconds
Clean programs should never have automatic numeric type conversions.
Instead use
data test;
input price $10.;
price2=compress(price,,'kd');
datalines;
825,563.25
;
run;
or
data test;
input price comma10.2;
price2=compress(put(price,best.),,'kd');
datalines;
825,563.25
;
run;
I would even define proper length for character variables according to the expected (infile documentation!) range.
Hello,
This serves the purpose but not sure if this is how you wanted it.
Example:
data test;
input price comma10.2.;
price2=compress(price,,'kd');
datalines;
825,563.25
;
run;
proc print data=test;
run;
Thanks
GP
@GPNaveen: bad programming practice:
24 data test; 25 input price comma10.2; 26 price2=compress(price,,'kd'); 27 datalines; NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 26:17 NOTE: The data set WORK.TEST has 1 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.02 seconds cpu time 0.00 seconds
Clean programs should never have automatic numeric type conversions.
Instead use
data test;
input price $10.;
price2=compress(price,,'kd');
datalines;
825,563.25
;
run;
or
data test;
input price comma10.2;
price2=compress(put(price,best.),,'kd');
datalines;
825,563.25
;
run;
I would even define proper length for character variables according to the expected (infile documentation!) range.
There are multiple ways to do this, but taking your example at face value. Consider using the COMPRESS function to remove the 'extra' characters.
data have;
input value $12.;
datalines;
123,456.78
$123,456.789
a1s2d3.wd40
run;
data want;
set have;
x = input(compress(value,,'dk'),best.);
put (_all_)(=);
run;
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!
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.