Help using Base SAS procedures

minus sign follows number

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

minus sign follows number

Hi
I’m getting number data, where the minus sign is at the and instead of in front.
is there a possibility to change the format with Proc Formt ? I’m not so familiar with this function.
Thanks for help.

ist    
ANLN1                  BUKRS       ANLKL           KANSW01       MENGE
000002500001      0001           00001258      8300.00-            1.000
000002500002      9600           00001258      20213.40-          1.000
000002500003      0300           00001258      28992.05           4.000
000002500004      0340           00001258      67450.00-          1.000
000002500008      0001           00001258      4001774.94      68.000
000002500011      2000           00001258      11306.65-           1.000
000002500013      0400           00001258      350451.05-      18.000
000002500018      2250           00001258       0.000
000002500019      0001           00001258       0.000

Soll

ANLN1                  BUKRS       ANLKL           KANSW01       MENGE

000002500001      0001           00001258      -8300.00            1.000

000002500002      9600           00001258      -20213.40          1.000

000002500003      0300           00001258      28992.05           4.000

000002500004      0340           00001258      -67450.00         1.000

000002500008      0001           00001258      4001774.94      68.000

000002500011      2000           00001258      -11306.65         1.000

000002500013      0400           00001258      -350451.05      18.000

000002500018      2250           00001258       0.000

000002500019      0001           00001258       0.000
   
My Approach:


Data BASIS (drop=KANSW01_D));
retain ANLN1 BUKRS KANSW01 MENGE;
set BASIS (rename=(KANSW01=KANSW01_D));
length   KANSW01 8.;

if index(KANSW01_D,'-') > 0 then
  do;
   KANSW01=input(cats('-',substr(KANSW01_D,1,index(KANSW01_D,'-')-1)),12.2);
  end;
run;


Accepted Solutions
Solution
‎02-19-2013 03:37 AM
Super Contributor
Posts: 259

Re: minus sign follows number

SAS has an informat to convert trailing + or -, named TrailSgn.

Data BASIS (drop=KANSW01_D);

retain ANLN1 BUKRS KANSW01 MENGE;

set BASIS (rename=(KANSW01=KANSW01_D));

length   KANSW01 8.;

format Kansw01 12.2;

Kansw01 = input(Str_Kansw01, trailsgn12.);
run;

View solution in original post


All Replies
Solution
‎02-19-2013 03:37 AM
Super Contributor
Posts: 259

Re: minus sign follows number

SAS has an informat to convert trailing + or -, named TrailSgn.

Data BASIS (drop=KANSW01_D);

retain ANLN1 BUKRS KANSW01 MENGE;

set BASIS (rename=(KANSW01=KANSW01_D));

length   KANSW01 8.;

format Kansw01 12.2;

Kansw01 = input(Str_Kansw01, trailsgn12.);
run;

Frequent Contributor
Posts: 81

Re: minus sign follows number

Hi Sniff,

Try this method too, it is working fine:-

=================================

data raw;

informat MENGE 5.2;

input ANLN1 BUKRS ANLKL KANSW01 : $10. MENGE ;

format MENGE 5.3;

datalines;

000002500001 0001 00001258 8300.00- 1.000

000002500002 9600 00001258 20213.42- 1.000

;

run;

data final(drop=KANSW01_N);

set raw(rename=(KANSW01=KANSW01_N));

if index(KANSW01_N,'-') > 0 then do;

KANSW01=input(compress(KANSW01_N,'-'),8.);

KANSW01=-ABS(KANSW01);

end;

run;

=======================================================

Output as required:-

=============================================

   Obs    MENGE     ANLN1     BUKRS    ANLKL     KANSW01

    1     1.000    2500001        1     1258     -8300.00

     2     1.000    2500002     9600     1258    -20213.42

==============================================

/Daman

Super Contributor
Posts: 276

Re: minus sign follows number

Hi..

I Always Suggest Solution..

But If you want more tricky Solution try This..:-) :-)

Data test;

input ANLN1 BUKRS ANLKL KANSW01 $9. MENGE;

cards;

000002500001 0001 00001258 8300.00-  1.000

000002500002 9600 00001258 20213.40  1.000

;

run;

Data My(Rename=(new=KANSW01) Drop=KANSW01);

set test;

if substr(KANSW01,length(KANSW01),1) eq '-' then

new=input(substr(KANSW01,length(KANSW01),1)||substr(KANSW01,1,length(KANSW01)-1),8.2);

else new=KANSW01;

run;

Regards.

Sanjeev.K

Respected Advisor
Posts: 3,777

Re: minus sign follows number

Why not use the proper INFORMAT TRAILSGNw.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 260 views
  • 3 likes
  • 5 in conversation