Hello, I have a question about the data processing.
I have a table, have three columns, e.g. V1, V2 and V3.
The system will standardize the variables, will generate new column to store the results, e.g. STD_v1, STD_v2, STD_v3.
But sometimes, value of a column only contains value 0, hence the STD_V# will not be generated.
Can please suggest that code to
1. determine if the STD results exist, e.g.STD_v1, STD_v2 etc.
2. if yes, do nothing, but if no, generate a new column with values 0 in that column? e.g. if STD_v1 doesnot exist, generate a column in table with name STD_v1, and all values for that column is 0.
Many thanks
Or more simply
data want;
set have;
std_v1=sum(std_v1,0);
std_v2=sum(std_v2,0);
std_v3=sum(std_v3,0);
run;
If the columns do not exist they will be created automatically.
It is not clear what you are asking. What is your input? What do you want out as your output?
Are you asking to convert missing standard deviations to zero? Note there is a difference between a variable with a std of zero and one where std is not defined. Try this example:
data test;
input x y ;
n=n(x,y);
std=std(x,y);
cards;
1 1
1 2
. 1
. .
;
proc print; run;
Obs x y n std 1 1 1 2 0.00000 2 1 2 2 0.70711 3 . 1 1 . 4 . . 0 .
Hello,
data std_zeros;
if _N_=0 then set have nobs=n;
do i=1 to n;
std_v1=0;
std_v2=0;
std_v3=0;
output;
end;
drop i;
run;
data want;
merge std_zeros have;
run;
Or more simply
data want;
set have;
std_v1=sum(std_v1,0);
std_v2=sum(std_v2,0);
std_v3=sum(std_v3,0);
run;
If the columns do not exist they will be created automatically.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.