Hi,
How to give required auto format to a NUMERIC variable in a datastep(without Macros)
For eg:
Numaric Variable values are as follow
A = 1.0, 12.30, 11.07, 7.70, 0.0, 17.71
I want them to be like
Numeric, B = 1, 12.3, 11.07, 7.7, 0, 17.71
Thanks in Advance
Santosh
Doe the "best." format not give you what you want?
data _null_;
do A = 1.0, 12.30, 11.07, 7.70, 0.0, 17.71;
put a 8.2 a best.;
output;
end;
run;
Doe the "best." format not give you what you want?
data _null_;
do A = 1.0, 12.30, 11.07, 7.70, 0.0, 17.71;
put a 8.2 a best.;
output;
end;
run;
It works absolutely fine
Thank you So much!
Removing leading and trailing 0s and blanks from a numeric variable(from display or char variable)
Be careful 'proc print' and 'put' can be decieving
HAVE
====
1.0
12.30
11.07
7.70
0.0
17.71
WANT
====
1
12.3
11.07
7.7
0
17.71
But I get when surrounding my put statement with '*'
*1*
* 1*
* 1*
*1 *
WANTED
======
*1* or just 1
WORKING CODE
============
Thanks to data _null_ old post
CutZro=substrn(a[i],1,max(5,a[i]));
FULL SOLUTION
=============
data chrCutZro;
length CutZro $5;
array A[6] (1.0, 12.30, 11.07, 7.70, 0.0, 17.71);
do i=1 to 6;
CutZro=substrn(a[i],1,max(5,a[i]));
put '*' CutZro +(-1) '*';
put '*' a[i] best. '*';
leading_blanks=put(a[i],best.);
put '*' leading_blanks $char12. '*';
leading_blanks_left=put(a[i],best. -l);
put '*' leading_blanks_left $char12. '*';
end;
run;quit;
substrn *1*
best. * 1*
char12 * 1*
best -L *1 *
substrn *12.3*
best. * 12.3*
char12 * 12.3*
best -L *12.3 *
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.