BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jonison
Fluorite | Level 6

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
gamotte
Rhodochrosite | Level 12

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.

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

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     .

gamotte
Rhodochrosite | Level 12

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;
gamotte
Rhodochrosite | Level 12

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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 539 views
  • 0 likes
  • 3 in conversation