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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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