<?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 what would be the best way for ClaimID defined as char or numer in different dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/what-would-be-the-best-way-for-ClaimID-defined-as-char-or-numer/m-p/797306#M263713</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Hi, I have the scenario that I have to use retain statement for claimID variable. When some data have ClaimID as numeric value and some have as character value, can I create a macro that passes through with checking the ClaimID type?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I need to create something like&amp;nbsp;%if CLAIMID = numeric value %then %do;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; work.createclaimID;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%if CLAIMID = numeric value %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; length INI_ClaimID &lt;STRONG&gt;8.&lt;/STRONG&gt; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set sortedsrc;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by MemID&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; retain INI_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if first.MemID then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; INI_ClaimID&amp;nbsp;&amp;nbsp; = &lt;STRONG&gt;.&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%if CLAIMID = character value %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; length INI_ClaimID $60&lt;STRONG&gt;.&lt;/STRONG&gt; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set sortedsrc;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by MemID&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; retain INI_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if first.MemID then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; INI_ClaimID&amp;nbsp;&amp;nbsp; = ‘ ‘;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;</description>
    <pubDate>Fri, 18 Feb 2022 19:32:11 GMT</pubDate>
    <dc:creator>JenniferK</dc:creator>
    <dc:date>2022-02-18T19:32:11Z</dc:date>
    <item>
      <title>what would be the best way for ClaimID defined as char or numer in different dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-would-be-the-best-way-for-ClaimID-defined-as-char-or-numer/m-p/797306#M263713</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Hi, I have the scenario that I have to use retain statement for claimID variable. When some data have ClaimID as numeric value and some have as character value, can I create a macro that passes through with checking the ClaimID type?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I need to create something like&amp;nbsp;%if CLAIMID = numeric value %then %do;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; work.createclaimID;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%if CLAIMID = numeric value %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; length INI_ClaimID &lt;STRONG&gt;8.&lt;/STRONG&gt; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set sortedsrc;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by MemID&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; retain INI_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if first.MemID then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; INI_ClaimID&amp;nbsp;&amp;nbsp; = &lt;STRONG&gt;.&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%if CLAIMID = character value %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; length INI_ClaimID $60&lt;STRONG&gt;.&lt;/STRONG&gt; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set sortedsrc;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by MemID&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; retain INI_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if first.MemID then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; INI_ClaimID&amp;nbsp;&amp;nbsp; = ‘ ‘;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 19:32:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-would-be-the-best-way-for-ClaimID-defined-as-char-or-numer/m-p/797306#M263713</guid>
      <dc:creator>JenniferK</dc:creator>
      <dc:date>2022-02-18T19:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: what would be the best way for ClaimID defined as char or numer in different dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-would-be-the-best-way-for-ClaimID-defined-as-char-or-numer/m-p/797317#M276731</link>
      <description>&lt;P&gt;Here is the solution if anybody needs it.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/** sample data set **/&lt;BR /&gt;data sortedsrc;&lt;BR /&gt;claimid=123;&lt;BR /&gt;memid=1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data sortedsrc2;&lt;BR /&gt;claimid='123';&lt;BR /&gt;memid=1;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%macro lst(dsn);&lt;BR /&gt;/** open dataset **/&lt;BR /&gt;%let dsid=%sysfunc(open(&amp;amp;dsn));&lt;BR /&gt;&lt;BR /&gt;/** retrieve the type of the variable claimid and place in macro variable &amp;amp;typ **/&lt;BR /&gt;%let x=%sysfunc(varnum(&amp;amp;dsid,claimid));&lt;BR /&gt;%let typ=%sysfunc(vartype(&amp;amp;dsid,&amp;amp;x));&lt;BR /&gt;&lt;BR /&gt;/** close dataset **/&lt;BR /&gt;%let rc=%sysfunc(close(&amp;amp;dsid));&lt;BR /&gt;&lt;BR /&gt;data final_&amp;amp;dsn;&lt;BR /&gt;set &amp;amp;dsn;&lt;BR /&gt;by MemID;&lt;BR /&gt;retain INI_:;&lt;BR /&gt;&lt;BR /&gt;%if &amp;amp;typ = C %then %do;&lt;BR /&gt;length INI_ClaimID $60. ;&lt;BR /&gt;if first.MemID then do;&lt;BR /&gt;INI_ClaimID = ' ';&lt;BR /&gt;end;&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;length INI_ClaimID 8. ;&lt;BR /&gt;if first.MemID then do;&lt;BR /&gt;INI_ClaimID = .;&lt;BR /&gt;end;&lt;BR /&gt;%end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%mend lst;&lt;BR /&gt;%lst(sortedsrc);&lt;BR /&gt;%lst(sortedsrc2);&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 21:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-would-be-the-best-way-for-ClaimID-defined-as-char-or-numer/m-p/797317#M276731</guid>
      <dc:creator>JenniferK</dc:creator>
      <dc:date>2022-02-18T21:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: what would be the best way for ClaimID defined as char or numer in different dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-would-be-the-best-way-for-ClaimID-defined-as-char-or-numer/m-p/797321#M278637</link>
      <description>&lt;P&gt;Congrats on finding the answer yourself &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One suggestion for your code, to make it more general, you can use CALL MISSING which applies to both numeric/character variables instead of assigning missing values. Length statements usually need to be before the SET statement for variables that already exist as well but if it worked for you I guess you're fine.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data final_&amp;amp;dsn;&lt;BR /&gt;&lt;BR /&gt;%if &amp;amp;typ = C %then 
      length INI_ClaimID $60. ;
%else 
     length INI_ClaimID 8. ;&lt;BR /&gt;&lt;BR /&gt;
set &amp;amp;dsn;
by MemID;
retain INI_:;

if first.MemID then call missing(INI_ClaimID);

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Feb 2022 21:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-would-be-the-best-way-for-ClaimID-defined-as-char-or-numer/m-p/797321#M278637</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-02-18T21:20:00Z</dc:date>
    </item>
  </channel>
</rss>

