SAS Data Management

SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop, SAS Data Preparation and others
BookmarkSubscribeRSS Feed
satish123
Fluorite | Level 6

Dear all,

i've a dataset like given bellow

                

ABCD
N363636
Mean9581.17289791.52621366.1106
SD2965.86262982.0749 398.3543
Geo_Mean9170.2867 2.0864674 1312.3213
CV13.95511 13.455669 0.159741

 

Now i need to give 3 decimal places for the variables 'B' & 'C', and 5 significant digits for the variable 'D'. But these decimal places and significant digits should not be applyed for observations of 'N'. i had tried many things like format, length and etc. but it didn't work well. the output should be like given bellow.


ABCD
N363636
Mean9581.1729791.5261366.1
SD2965.8622982.074398.35
Geo_Mean9170.2862.086 1312.3
CV13.955 13.4550.15974


i'm excited to find is it really possible? if so, can anyone tell me how? or it is possible by transforming the variables?

Thanks in advance

1 REPLY 1
GraphGuy
Meteorite | Level 14

Here's one brute-force way to do it, converting the numeric values to character, and controlling the number of decimals shown when you create the character values:

 

data foo;
length A $50;
input A B C D;
datalines;
N	36	36	36
Mean	9581.1728	9791.5262	1366.1106
SD	2965.8626	2982.0749	398.3543
Geo_Mean	9170.2867	2.0864674	1312.3213
CV	13.95511	13.455669	0.159741
;
run;

data foo; set foo;
length B_string C_string D_string $20;
if A='N' then do;
 B_string=put(B,comma5.0);
 C_string=put(C,comma5.0);
 D_string=put(D,comma5.0);
 end;
else do;
 B_string=put(B,comma20.3);
 C_string=put(C,comma20.3);
 D_string=put(D,comma20.1);
 end;

proc print data=foo noobs label;
label B_string='B' C_string='C' D_string='D'; 
var A / style={just=center};
var B_string / style={just=right};
var C_string / style={just=right};
var D_string / style={just=right};
run;

undefined 


undefined

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1666 views
  • 0 likes
  • 2 in conversation