BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sayanapex06
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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

View solution in original post

3 REPLIES 3
GPNaveen
Fluorite | Level 6

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

Kurt_Bremser
Super User

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

ArtC
Rhodochrosite | Level 12

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 3918 views
  • 0 likes
  • 4 in conversation