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

Hi All,

 

I have a requirement where the input is coming from the Easytrieve in which the acceptable numeric format is 100.00-. I need to convert this into  SAS numeric format. Can some one help me in achieving this?

 

Input            Output

100.00-        -100.00

 

This field is the variable one.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data x;
input x trailsgn32.;
cards;
100.00-   
34.32-
29
64.89
;
run;
proc print;run;

View solution in original post

7 REPLIES 7
PGStats
Opal | Level 21

You can define your own informat to read such numbers

 


/* Informat function to read numbers possibly suffixed with a
   minus sign. */ 
proc fcmp outlib=work.fcmp.format;
function EasytrieveNumber(text $);
m = indexc(text, "-");
if m = length(text) then return (-input(substr(text,1,m-1), best.));
else return (input(text, best.));
endsub;
run;

options cmplib=(work.fcmp);

proc format;
invalue EasytrieveNumber(default=32) 
OTHER = [EasytrieveNumber()];
run;

data have;
input a :EasytrieveNumber10.;
format a 8.2;
cards;
100.00-
100.00
;

proc print data=have; run;
                                  Obs           a

                                   1      -100.00
                                   2       100.00
PG
Ksharp
Super User
data x;
input x trailsgn32.;
cards;
100.00-   
34.32-
29
64.89
;
run;
proc print;run;
SASInd
Obsidian | Level 7

Hi Ksharp,

 

TRAILSGNw. will only work for numeric values. In this case the input is coming as 100.00- which in my knowledge will only be read as a character value.

 

Thanks!

error_prone
Barite | Level 11

@SASInd: @Ksharp demonstrates that the format can be used to create normal numbers.

SASInd
Obsidian | Level 7

Thank you @Ksharp @error_prone & @Reeza 🙂

SASInd
Obsidian | Level 7
Yeah... But the question here is for converting the character data to a numeric format.
Reeza
Super User

@aadityapurohit3 wrote:
Yeah... But the question here is for converting the character data to a numeric format.

That's what @Ksharp solution does, you can use that format in the INPUT() statement. 

 

data x;
    input x $;
    cards;
100.00-   
34.32-
29
64.89
;
run;

data want;
    set x;
    char_x=input(x, trailsgn32.);
run;

proc print data=want;
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
  • 7 replies
  • 1607 views
  • 10 likes
  • 5 in conversation