<?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: How to Create the Additional Records in the  Data Based on Existed Data. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Create-the-Additional-Records-in-the-Data-Based-on/m-p/833630#M329562</link>
    <description>&lt;P&gt;Good question.&amp;nbsp; For my actual data the answer is 'Yes' because we only keeping the records that have the both at a particular visit.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Sep 2022 15:16:30 GMT</pubDate>
    <dc:creator>SASuserlot</dc:creator>
    <dc:date>2022-09-15T15:16:30Z</dc:date>
    <item>
      <title>How to Create the Additional Records in the  Data Based on Existed Data.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Create-the-Additional-Records-in-the-Data-Based-on/m-p/833006#M329295</link>
      <description>&lt;P&gt;I am sorry , If my title is confusing. I am came up with the title best of my ability.&amp;nbsp; I am looking to create an additional record easy way&amp;nbsp; based on the data available.&lt;/P&gt;
&lt;P&gt;For example:&amp;nbsp; In my data,&amp;nbsp; subjid =101 and Visit= V2, missing the&amp;nbsp; PARAMCD= BMI and same applies to the subjid=103 at visit= V1.&lt;/P&gt;
&lt;P&gt;So I am looking is there any easy way, I can check my subjects&amp;nbsp; missing PARAMCD='BMI' at a particular visit and if it missing at a particular Visit, I need to calculate the BMI ( BMI= wit/(hit*hit))?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vital;
input subjid visit$ paramcd$ aval ;
cards;
101 V1 hit 1.60 
101 V1 wit 80 
101 V1 BMI 31.2
101 V2 hit 1.60 
101 V2 wit 90 
103 V1 hit 1.502 
103 V1 wit 74 
103 V2 hit 1.502 
103 V2 wit 75 
103 V2 BMI 33.2 
;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_0-1663017337564.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75164iAC0651274FE8A7D5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_0-1663017337564.png" alt="SASuserlot_0-1663017337564.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 21:16:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Create-the-Additional-Records-in-the-Data-Based-on/m-p/833006#M329295</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-09-12T21:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create the Additional Records in the  Data Based on Existed Data.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Create-the-Additional-Records-in-the-Data-Based-on/m-p/833049#M329307</link>
      <description>&lt;P&gt;This task can be solved with a single data step, but you need to be sure that BMI is always the last obs in each visit. Unfortunately i don't see a way to ensure this by code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_one;
   set sorted;
   by subjid visit;

   retain _hit _wit;

   if first.visit then do;
      call missing(_hit, _wit);
   end;

   select (lowcase(paramcd));
      when ('hit') _hit = aval;
      when ('wit') _wit = aval;
      otherwise;
   end;

   output;

   if last.visit and lowcase(paramcd) ^= 'bmi' then do;
      paramcd = 'BMI';
      aval = _wit / (_hit * _hit);
      output;
   end;

   drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Another idea, with longer runtime:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=sorted out=transposed(drop=_name_);
   by subjid visit;
   var aval;
   id paramcd;
run;

data filled;
   set transposed;

   if missing(bmi) then do;
      bmi = wit / (hit * hit);
   end;
run;

proc transpose data=filled out=want_transpose(rename= (col1 = aval)) name=paramcd;
   by subjid visit;
   var hit wit bmi;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Sep 2022 06:23:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Create-the-Additional-Records-in-the-Data-Based-on/m-p/833049#M329307</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-09-13T06:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create the Additional Records in the  Data Based on Existed Data.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Create-the-Additional-Records-in-the-Data-Based-on/m-p/833073#M329312</link>
      <description>&lt;P&gt;Is it safe to assume that hit / wit is always there ?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 09:17:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Create-the-Additional-Records-in-the-Data-Based-on/m-p/833073#M329312</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-09-13T09:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create the Additional Records in the  Data Based on Existed Data.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Create-the-Additional-Records-in-the-Data-Based-on/m-p/833092#M329319</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vital;
input subjid visit$ paramcd$ aval ;
cards;
101 V1 hit 1.60 
101 V1 wit 80 
101 V1 BMI 31.2
101 V2 hit 1.60 
101 V2 wit 90 
103 V1 hit 1.502 
103 V1 wit 74 
103 V2 hit 1.502 
103 V2 wit 75 
103 V2 BMI 33.2 
;
RUN;

proc sql;
create table want as
select a.*,b.aval as aval
 from (select * from
(select distinct subjid from vital),
(select distinct visit from vital),
(select distinct paramcd from vital)
) as a
natural left join vital as b;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Sep 2022 12:01:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Create-the-Additional-Records-in-the-Data-Based-on/m-p/833092#M329319</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-09-13T12:01:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create the Additional Records in the  Data Based on Existed Data.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Create-the-Additional-Records-in-the-Data-Based-on/m-p/833630#M329562</link>
      <description>&lt;P&gt;Good question.&amp;nbsp; For my actual data the answer is 'Yes' because we only keeping the records that have the both at a particular visit.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 15:16:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Create-the-Additional-Records-in-the-Data-Based-on/m-p/833630#M329562</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-09-15T15:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create the Additional Records in the  Data Based on Existed Data.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Create-the-Additional-Records-in-the-Data-Based-on/m-p/833640#M329566</link>
      <description>&lt;P&gt;Thank you for your suggestion&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;.&amp;nbsp; I think you missing to Include the BMI calculation in the code, I am getting missing values ( AVAL)&amp;nbsp; for the Records (BMI) Newly created. and I also see a note in the log, Is it gonna run into any issues?&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;NOTE: The execution of this query involves performing one or more Cartesian product joins that can not be optimized.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_0-1663255812419.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75285i812DF21514056506/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_0-1663255812419.png" alt="SASuserlot_0-1663255812419.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 15:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Create-the-Additional-Records-in-the-Data-Based-on/m-p/833640#M329566</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-09-15T15:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create the Additional Records in the  Data Based on Existed Data.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Create-the-Additional-Records-in-the-Data-Based-on/m-p/833642#M329567</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;. It worked and do the job I wanted.&amp;nbsp; Thank you for pointing out on BMI being the last in Each Visit.&amp;nbsp; I can assign the Numeric numbers to the paramcds and Make sure it is always at the last.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 15:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Create-the-Additional-Records-in-the-Data-Based-on/m-p/833642#M329567</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-09-15T15:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create the Additional Records in the  Data Based on Existed Data.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Create-the-Additional-Records-in-the-Data-Based-on/m-p/833819#M329651</link>
      <description>&lt;P&gt;After getting WANT dataset ,it is very easy to get BMI.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data vital;
input subjid visit$ paramcd$ aval ;
cards;
101 V1 hit 1.60 
101 V1 wit 80 
101 V1 BMI 31.2
101 V2 hit 1.60 
101 V2 wit 90 
103 V1 hit 1.502 
103 V1 wit 74 
103 V2 hit 1.502 
103 V2 wit 75 
103 V2 BMI 33.2 
;
RUN;

proc sql;
create table want as
select a.*,b.aval as aval
 from (select * from
(select distinct subjid from vital),
(select distinct visit from vital),
(select distinct paramcd from vital)
) as a
natural left join vital as b;
quit;
data want;
 merge want want(keep=aval rename=(aval=hit) firstobs=2 ) want(keep=aval rename=(aval=wit) firstobs=3 );
 if paramcd='BMI' and missing(aval) then aval=wit/hit**2;
 drop hit wit ;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Sep 2022 11:51:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Create-the-Additional-Records-in-the-Data-Based-on/m-p/833819#M329651</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-09-16T11:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create the Additional Records in the  Data Based on Existed Data.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Create-the-Additional-Records-in-the-Data-Based-on/m-p/834860#M330024</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2022 15:14:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Create-the-Additional-Records-in-the-Data-Based-on/m-p/834860#M330024</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-09-23T15:14:59Z</dc:date>
    </item>
  </channel>
</rss>

