<?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: Output dataset with available avisit for each subject in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Output-dataset-with-available-avisit-for-each-subject/m-p/935651#M367860</link>
    <description>Yes, it is working but getting following note&lt;BR /&gt;1983 %put &amp;amp;var1 &amp;amp;var3 &amp;amp;var4 &amp;amp;var5 &amp;amp;var6 &amp;amp;var2 &amp;amp;num;&lt;BR /&gt;1200 1320 1360 1400 1520 1240 6&lt;BR /&gt;1984&lt;BR /&gt;1985 %let var1=1;&lt;BR /&gt;1986 %let var2=2;&lt;BR /&gt;1987 %let var3=3;&lt;BR /&gt;1988 %let var4=4;&lt;BR /&gt;1989 %let var5=5;&lt;BR /&gt;1990 %let var6=6;&lt;BR /&gt;1991&lt;BR /&gt;1992 %let num=6;&lt;BR /&gt;1993&lt;BR /&gt;1994 data adsl_vis;&lt;BR /&gt;1995 set adsl(keep=usubjid subjid);&lt;BR /&gt;1996 do i=1 to &amp;amp;num.;&lt;BR /&gt;1997 avisitn=symget('var'||left(i));&lt;BR /&gt;1998 output;&lt;BR /&gt;1999 end;&lt;BR /&gt;2000 run;&lt;BR /&gt;&lt;BR /&gt;NOTE: Numeric values have been converted to character values at the places given by:&lt;BR /&gt;(Line):(Column).&lt;BR /&gt;1997:32&lt;BR /&gt;NOTE: There were 351 observations read from the data set WORK.ADSL.&lt;BR /&gt;NOTE: The data set WORK.ADSL_VIS has 2106 observations and 4 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 12 Jul 2024 20:39:13 GMT</pubDate>
    <dc:creator>chinna0369</dc:creator>
    <dc:date>2024-07-12T20:39:13Z</dc:date>
    <item>
      <title>Output dataset with available avisit for each subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-dataset-with-available-avisit-for-each-subject/m-p/935646#M367856</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to output records for each record with available avisit by using do loop as below. But I am getting below erro, please let me know what I am missing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let var1=1;
%let var2=2;
%let var3=3;
%let var4=4;
%let var5=5;
%let var6=6;

%let num=6;

data adsl_vis;
	set adsl(keep=usubjid subjid);
	do i=1 to &amp;amp;num;
	avisitn=&amp;amp;&amp;amp;var&amp;amp;i; 
	output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="chinna0369_0-1720814804182.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/98368i1F9088F75D3D9697/image-size/medium?v=v2&amp;amp;px=400" role="button" title="chinna0369_0-1720814804182.png" alt="chinna0369_0-1720814804182.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Chinna&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2024 20:07:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-dataset-with-available-avisit-for-each-subject/m-p/935646#M367856</guid>
      <dc:creator>chinna0369</dc:creator>
      <dc:date>2024-07-12T20:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: Output dataset with available avisit for each subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-dataset-with-available-avisit-for-each-subject/m-p/935648#M367857</link>
      <description>&lt;P&gt;Macro variables resolve before the data step starts to execute.&lt;/P&gt;
&lt;P&gt;So please describe what you want in a bit more detail. This macro approach is cumbersome and placing many values into macro variables is quite often not a good idea in general.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are using &amp;amp;i, which expects a macro variable named I to exist. The macro processor does not see data step variable values. If you must in a data step the function is SYMGET. (Please don't use data set's not defined )&lt;/P&gt;
&lt;PRE&gt;data adsl_vis;
/*	set adsl(keep=usubjid subjid);*/
	do i=1 to &amp;amp;num;
	   avisitn=symget('var'||left(i)); 
	output;
	end;
run;&lt;/PRE&gt;
&lt;P&gt;However than would create 6 output records for each one read, is that the desire?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However if the &lt;STRONG&gt;purpose&lt;/STRONG&gt; of this is to create a sequence number then perhaps:&lt;/P&gt;
&lt;PRE&gt;data adsl_vis;
   set adsl(keep=usubjid subjid);
   avisitn=_n_;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2024 20:22:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-dataset-with-available-avisit-for-each-subject/m-p/935648#M367857</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-07-12T20:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: Output dataset with available avisit for each subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-dataset-with-available-avisit-for-each-subject/m-p/935649#M367858</link>
      <description>In this example I have 6 visitnum I want to create a dataset with all the records in ADSL with all those 6 visits.</description>
      <pubDate>Fri, 12 Jul 2024 20:36:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-dataset-with-available-avisit-for-each-subject/m-p/935649#M367858</guid>
      <dc:creator>chinna0369</dc:creator>
      <dc:date>2024-07-12T20:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: Output dataset with available avisit for each subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-dataset-with-available-avisit-for-each-subject/m-p/935650#M367859</link>
      <description>For example, I have 10 records in adsl with unique id. I want my final data 6*10 60 records should be there with each record and each visit.</description>
      <pubDate>Fri, 12 Jul 2024 20:37:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-dataset-with-available-avisit-for-each-subject/m-p/935650#M367859</guid>
      <dc:creator>chinna0369</dc:creator>
      <dc:date>2024-07-12T20:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: Output dataset with available avisit for each subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-dataset-with-available-avisit-for-each-subject/m-p/935651#M367860</link>
      <description>Yes, it is working but getting following note&lt;BR /&gt;1983 %put &amp;amp;var1 &amp;amp;var3 &amp;amp;var4 &amp;amp;var5 &amp;amp;var6 &amp;amp;var2 &amp;amp;num;&lt;BR /&gt;1200 1320 1360 1400 1520 1240 6&lt;BR /&gt;1984&lt;BR /&gt;1985 %let var1=1;&lt;BR /&gt;1986 %let var2=2;&lt;BR /&gt;1987 %let var3=3;&lt;BR /&gt;1988 %let var4=4;&lt;BR /&gt;1989 %let var5=5;&lt;BR /&gt;1990 %let var6=6;&lt;BR /&gt;1991&lt;BR /&gt;1992 %let num=6;&lt;BR /&gt;1993&lt;BR /&gt;1994 data adsl_vis;&lt;BR /&gt;1995 set adsl(keep=usubjid subjid);&lt;BR /&gt;1996 do i=1 to &amp;amp;num.;&lt;BR /&gt;1997 avisitn=symget('var'||left(i));&lt;BR /&gt;1998 output;&lt;BR /&gt;1999 end;&lt;BR /&gt;2000 run;&lt;BR /&gt;&lt;BR /&gt;NOTE: Numeric values have been converted to character values at the places given by:&lt;BR /&gt;(Line):(Column).&lt;BR /&gt;1997:32&lt;BR /&gt;NOTE: There were 351 observations read from the data set WORK.ADSL.&lt;BR /&gt;NOTE: The data set WORK.ADSL_VIS has 2106 observations and 4 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 12 Jul 2024 20:39:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-dataset-with-available-avisit-for-each-subject/m-p/935651#M367860</guid>
      <dc:creator>chinna0369</dc:creator>
      <dc:date>2024-07-12T20:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: Output dataset with available avisit for each subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-dataset-with-available-avisit-for-each-subject/m-p/935652#M367861</link>
      <description>By the way the variable which we are creating should be numeric AVISITN.</description>
      <pubDate>Fri, 12 Jul 2024 20:41:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-dataset-with-available-avisit-for-each-subject/m-p/935652#M367861</guid>
      <dc:creator>chinna0369</dc:creator>
      <dc:date>2024-07-12T20:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: Output dataset with available avisit for each subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-dataset-with-available-avisit-for-each-subject/m-p/935657#M367862</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/117414"&gt;@chinna0369&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;By the way the variable which we are creating should be numeric AVISITN.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;avisitn=input(symget('var'||left(i)),8.);&lt;/PRE&gt;
&lt;P&gt;Basic use of INPUT to guarantee numeric result (and a hint why macro variables may not be a good approach)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to add the same set of avisitn values to each record in the data set:&lt;/P&gt;
&lt;PRE&gt;data avisitn_data;
   input avisitn;
datalines;
1
2
3
4
5
6
;

Proc sql create table adsl_vis as
   select a.usubjid,a.subjid
          ,b.avisitn
   from adsl as a,avisitn_data as b
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;The Proc SQL JOINS two data sets in a Cartesian Join, meaning every observation in one set is combined with every observation in a different data set.&lt;/P&gt;
&lt;P&gt;IF however the data set Adsl already has values of Avisitn and you want to select only matching ones:&lt;/P&gt;
&lt;PRE&gt;Proc sql create table want as
   select a.*
   from adsl as a
        right join
        avisitn_data a b
        on a.avisitn=b.avisitn
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;Note that in neither case do you have to create multiple macro variables, attempt to use the sometimes flaky macro indirect reference or even count the number of values involved. Just place the list into the data set and Proc Sql will do the work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2024 21:36:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-dataset-with-available-avisit-for-each-subject/m-p/935657#M367862</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-07-12T21:36:01Z</dc:date>
    </item>
  </channel>
</rss>

