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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

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

4 REPLIES 4
andreas_lds
Jade | Level 19

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;

damanaulakh88
Obsidian | Level 7

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

kuridisanjeev
Quartz | Level 8

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

data_null__
Jade | Level 19

Why not use the proper INFORMAT TRAILSGNw.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 2011 views
  • 3 likes
  • 5 in conversation