<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: add new columes with value with 'if' conditons in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/add-new-columes-with-value-with-if-conditons/m-p/609978#M177615</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 06 Dec 2019 15:07:43 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2019-12-06T15:07:43Z</dc:date>
    <item>
      <title>add new columes with value with 'if' conditons</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-new-columes-with-value-with-if-conditons/m-p/609973#M177612</link>
      <description>&lt;P&gt;Hello, I have a question about the data processing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table, have three columns, e.g. V1, V2 and V3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The system will standardize the variables, will generate new column to store the results, e.g. STD_v1, STD_v2, STD_v3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But sometimes, value of a column only contains value 0, hence the STD_V# will not be generated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can please suggest that code to&lt;/P&gt;&lt;P&gt;1. determine if the STD results exist, e.g.STD_v1, STD_v2 etc.&lt;/P&gt;&lt;P&gt;2. if yes, do nothing, but if no, generate a new column&amp;nbsp;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 14:54:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-new-columes-with-value-with-if-conditons/m-p/609973#M177612</guid>
      <dc:creator>Jonison</dc:creator>
      <dc:date>2019-12-06T14:54:13Z</dc:date>
    </item>
    <item>
      <title>Re: add new columes with value with 'if' conditons</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-new-columes-with-value-with-if-conditons/m-p/609977#M177614</link>
      <description>&lt;P&gt;It is not clear what you are asking.&amp;nbsp; What is your input? What do you want out as your output?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&amp;nbsp; Try this example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 input x y ;
 n=n(x,y);
 std=std(x,y);
cards;
1 1
1 2
. 1
. .
;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    x    y    n      std

 1     1    1    2    0.00000
 2     1    2    2    0.70711
 3     .    1    1     .
 4     .    .    0     .

&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Dec 2019 15:05:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-new-columes-with-value-with-if-conditons/m-p/609977#M177614</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-06T15:05:28Z</dc:date>
    </item>
    <item>
      <title>Re: add new columes with value with 'if' conditons</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-new-columes-with-value-with-if-conditons/m-p/609978#M177615</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Dec 2019 15:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-new-columes-with-value-with-if-conditons/m-p/609978#M177615</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-12-06T15:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: add new columes with value with 'if' conditons</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-new-columes-with-value-with-if-conditons/m-p/609980#M177616</link>
      <description>&lt;P&gt;Or more simply&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
std_v1=sum(std_v1,0);
std_v2=sum(std_v2,0);
std_v3=sum(std_v3,0);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the columns do not exist they will be created automatically.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 15:15:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-new-columes-with-value-with-if-conditons/m-p/609980#M177616</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-12-06T15:15:00Z</dc:date>
    </item>
  </channel>
</rss>

