Hello,
I have a dataset of model output from proc mixed that you can see below:
data WORK.LOC_S;
infile datalines dsd truncover;
input Effect:$13. Estimate:D8.4 StdErr:D8.4 DF:BEST4. tValue:7.2 Probt:PVALUE6.4 Alpha:BEST6. Lower:D8.4 Upper:D8.4;
format Estimate D8.4 StdErr D8.4 DF BEST4. tValue 7.2 Probt PVALUE6.4 Alpha BEST6. Lower D8.4 Upper D8.4;
label StdErr="Standard Error" tValue="t Value" Probt="Pr > |t|";
datalines;
Intercept 6.0372 0.9943 121 6.07 <.0001 0.05 4.0689 8.0056
locnum 0.9745 0.2117 31.3 4.60 <.0001 0.05 0.5429 1.4060
visit -0.3080 0.1693 66.3 -1.82 0.0734 0.05 -0.6459 0.03003
locnum*locnum -0.04245 0.01383 17.5 -3.07 0.0068 0.05 -0.07158 -0.01333
I want to combine the estimate and confidence interval into one variable, but when I do so, the leading zero for the negative decimals is lost.
Here is my code:
data loc;
set loc_s;
Est95CL=put(Estimate,Z5.3)||' ('||compress(put(Lower,Z5.3)||','||put(Upper,Z5.3)||')');
drop estimate lower upper stderr df tvalue alpha;
run;
And this is what happens:
data WORK.LOC;
infile datalines dsd truncover;
input Effect:$13. Probt:PVALUE6.4 Est95CL:$19.;
format Probt PVALUE6.4;
label Probt="Pr > |t|";
datalines;
Intercept <.0001 6.037 (4.069,8.006)
locnum <.0001 0.974 (0.543,1.406)
visit 0.0734 -.308 (-.646,0.030)
locnum*locnum 0.0068 -.042 (-.072,-.013)
Does anyone know how to keep the zeros in front of the decimal points for the negative values?
5 characters does not leave enough room for 3 decimal places, a period, a negative sign and an extra zero. The computer was better at counting than the human, it normally is, so it removed the leading zero so it could fit the result into 5 characters.
2497 data have; 2498 input estimate lower upper ; 2499 list; 2500 cards; RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 2501 6.037 4.069 8.006 2502 0.974 0.543 1.406 2503 -.308 -.646 0.030 2504 -.042 -.072 -.013
Use a larger WIDTH on the format. I doubt you want to print values like -000.308 so do not use the Z format.
data want;
set have ;
test1=cat(put(estimate,6.3),' (',put(upper,6.3),',',put(lower,6.3),')');
run;
Result
Obs estimate lower upper test1 1 6.037 4.069 8.006 6.037 ( 8.006, 4.069) 2 0.974 0.543 1.406 0.974 ( 1.406, 0.543) 3 -0.308 -0.646 0.030 -0.308 ( 0.030,-0.646) 4 -0.042 -0.072 -0.013 -0.042 (-0.013,-0.072)
You use format Z5.3; with a negative number, you have 3 decimals, 1 decimal point and 1 sign, so SAS drops the leading zero in favor of the sign and keeping the 3 decimals.
In order to keep the zero, use another format or a larger length.
What is the range of your numbers, and how do you want them displayed?
Thanks for your response! I tried using d8.2 and that worked.
I got this output:
data WORK.LOC;
infile datalines dsd truncover;
input Effect:$13. Probt:PVALUE6.4 Est95CL:$28.;
format Probt PVALUE6.4;
label Probt="Pr > |t|";
datalines;
Intercept <.0001 6.037 (4.069,8.006)
locnum <.0001 0.974 (0.543,1.406)
visit 0.0734 -0.308 (-0.646,0.030)
locnum*locnum 0.0068 -0.042 (-0.072,-0.013)
;
increasing the width fixed it, thank you!
5 characters does not leave enough room for 3 decimal places, a period, a negative sign and an extra zero. The computer was better at counting than the human, it normally is, so it removed the leading zero so it could fit the result into 5 characters.
2497 data have; 2498 input estimate lower upper ; 2499 list; 2500 cards; RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 2501 6.037 4.069 8.006 2502 0.974 0.543 1.406 2503 -.308 -.646 0.030 2504 -.042 -.072 -.013
Use a larger WIDTH on the format. I doubt you want to print values like -000.308 so do not use the Z format.
data want;
set have ;
test1=cat(put(estimate,6.3),' (',put(upper,6.3),',',put(lower,6.3),')');
run;
Result
Obs estimate lower upper test1 1 6.037 4.069 8.006 6.037 ( 8.006, 4.069) 2 0.974 0.543 1.406 0.974 ( 1.406, 0.543) 3 -0.308 -0.646 0.030 -0.308 ( 0.030,-0.646) 4 -0.042 -0.072 -0.013 -0.042 (-0.013,-0.072)
This worked thank you!!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.