<?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: create dataset for every observation in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/create-dataset-for-every-observation/m-p/597037#M16067</link>
    <description>Update to a version of SAS that was released sometime in the last 5 years.&lt;BR /&gt;</description>
    <pubDate>Wed, 16 Oct 2019 18:57:14 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-10-16T18:57:14Z</dc:date>
    <item>
      <title>create dataset for every observation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/create-dataset-for-every-observation/m-p/596735#M16005</link>
      <description>&lt;P&gt;data country;&lt;BR /&gt;input id name$ country$;&lt;BR /&gt;cards;&lt;BR /&gt;11 alex usa&lt;BR /&gt;12 reno uk&lt;BR /&gt;14 tanya india&lt;BR /&gt;15 john china&lt;BR /&gt;;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;as id columns is unique, i want to create new dataset based on id column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro createm;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select distinct id into :id1-:id99&lt;BR /&gt;from country;&lt;BR /&gt;quit;&lt;BR /&gt;%let cnum=&amp;amp;sqlobs;&lt;BR /&gt;%do i=1 %to &amp;amp;cnum;&lt;BR /&gt;%let dsname=name_&amp;amp;&amp;amp;id&amp;amp;i;&lt;/P&gt;&lt;P&gt;data &amp;amp;dsname;&lt;BR /&gt;set country;&lt;BR /&gt;where id =&amp;amp;id;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Options macrogen symbolgen mlogic mprint;&lt;BR /&gt;%createm;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here datasets are created but datasets are blank and i'm getting the error at where line :&amp;nbsp;ERROR: Syntax error while parsing WHERE clause.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when i change it to&amp;nbsp;where id ="&amp;amp;id" //then here also getting error :Where clause operator requires compatible variables.&lt;/P&gt;&lt;P&gt;also can i make it more dymanic here like&amp;nbsp;id1-:id99 ,can i pass a macro here without knowing the no of observations&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pls help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 03:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/create-dataset-for-every-observation/m-p/596735#M16005</guid>
      <dc:creator>adi121</dc:creator>
      <dc:date>2019-10-16T03:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: create dataset for every observation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/create-dataset-for-every-observation/m-p/596741#M16006</link>
      <description>&lt;P&gt;Here is one way.. This will handle when there are multiple obs for each id&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data country;
input id name$ country$;
cards;
11 alex usa
12 reno uk
14 tanya india
15 john china
;run;

data _null_;
   if _n_=1 then do;
      if 0 then set country;                                   
      declare hash h(dataset:"country(obs=0)", multidata:'y'); 
      h.definekey('id');                                     
      h.definedata(all:'y');                                    
      h.definedone();                                           
   end;
   do until(last.id);                                     
      set country;                                             
      by id;
      h.add();                                                  
   end;
   h.output(dataset:cats('id_', id));                                   
   h.clear();                                                   
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Oct 2019 04:44:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/create-dataset-for-every-observation/m-p/596741#M16006</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-16T04:44:53Z</dc:date>
    </item>
    <item>
      <title>Re: create dataset for every observation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/create-dataset-for-every-observation/m-p/596743#M16007</link>
      <description>&lt;P&gt;Note it is probably a terrible idea to create many tiny datasets, but let's play along and answer your questions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are making macro variables named ID1, ID2, etc. from the variable named NAME.&lt;/P&gt;
&lt;P&gt;That is why&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where id="&amp;amp;id";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is wrong.&lt;/P&gt;
&lt;P&gt;Use&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where name="&amp;amp;&amp;amp;id&amp;amp;i";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To your second question, you are already somewhat making it independent of the number of observations.&amp;nbsp; Only you set the upper bound on the number of observations at 99.&amp;nbsp; You could just raise that upper bound.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;into :id1-:id99999&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you can also just not set any upper bound.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;into :id1-&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Are you sure the values of your variable are valid strings to use in the name of the generated datasets?&amp;nbsp; Perhaps instead you should just name the datasets using the do loop index, then you are sure the value is valid in a name.&amp;nbsp; You could put the value into LABEL of the dataset instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsname=name_&amp;amp;i;

data &amp;amp;dsname (label="&amp;amp;&amp;amp;id&amp;amp;i");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 04:55:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/create-dataset-for-every-observation/m-p/596743#M16007</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-16T04:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: create dataset for every observation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/create-dataset-for-every-observation/m-p/597034#M16064</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;Thanks it is working fine now as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But you mentioned to make dynamic&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;into&lt;/SPAN&gt; :id1&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;so implenting above gives me syntax error.&lt;/P&gt;&lt;P&gt;I have to use &lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;into&lt;/SPAN&gt; :id1&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;&lt;/CODE&gt;id99.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 18:54:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/create-dataset-for-every-observation/m-p/597034#M16064</guid>
      <dc:creator>adi121</dc:creator>
      <dc:date>2019-10-16T18:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: create dataset for every observation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/create-dataset-for-every-observation/m-p/597037#M16067</link>
      <description>Update to a version of SAS that was released sometime in the last 5 years.&lt;BR /&gt;</description>
      <pubDate>Wed, 16 Oct 2019 18:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/create-dataset-for-every-observation/m-p/597037#M16067</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-16T18:57:14Z</dc:date>
    </item>
  </channel>
</rss>

