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;
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;
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;
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
Hi..
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
Why not use the proper INFORMAT TRAILSGNw.
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.
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.