<?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 extract all values from a variable and use it to subset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713786#M220265</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/111564"&gt;@HitmonTran&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;The Goal is to collect all AETERM, calulate the 95% CI, then merge each AETERM's 95% CI back to the the AETERM along with other variables that were calculated earlier (eg. # of Events, # of subjects experience the event)&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since your Aeterm variable values shown are all character I have to assume that you meant the confidence interval of another variable that is actually numeric. &lt;/P&gt;
&lt;P&gt;Here is an example getting multiple statistics, including upper and lower confidence limits of multiple numeric variables for each level of a character (or numeric) variable.&lt;/P&gt;
&lt;PRE&gt;proc summary data=sashelp.class nway;
   class sex;
   var height weight;
   output out=work.summary 
     min= mean= max= lclm= uclm= /autoname;
run;&lt;/PRE&gt;
&lt;P&gt;For each level of Sex there will be min, mean, max, lower confidence limit for the mean, upper confidence limit for the mea of each variable on the VAR statement.&lt;/P&gt;</description>
    <pubDate>Mon, 25 Jan 2021 00:07:32 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-01-25T00:07:32Z</dc:date>
    <item>
      <title>how to extract all values from a variable and use it to subset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713659#M220201</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;New to SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to extract all the values from a variable (AETERM) and&amp;nbsp; use those values to subset it later.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SUBJECT    AETERM 
 1         headache
 1         fever
 2         headache
 2         fatigue
 2         cough
 2         sneeze&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;current code&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*1*/
proc sort data=test out=test1;
  by subject;
   where aeterm='headache';
run;

/*2*/
proc sort data=test out=test2;
  by subject;
   where aeterm='fever';
run;

/*3*/
proc sort data=test out=test3;
  by subject;
   where aeterm='fatigue';
run;

/*4*/
proc sort data=test out=test4;
  by subject;
   where aeterm='cough';
run;

/*5*/
proc sort data=test out=test5;
  by subject;
   where aeterm='sneeze';
run;
 

 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Obviously the current code would not work if there are hundreds of AETERM. My goal is to macrotize or do something similar if possible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 06:08:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713659#M220201</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2021-01-24T06:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract all values from a variable and use it to subset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713665#M220205</link>
      <description>&lt;P&gt;If I were doing this with dataset SASHELP.CLASS, generating one dataset for each sex, I might code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=have;
  by name;
run;

data test_f (where=(sex="F"))
     test_m (where=(sex="M")) ;
  set sashelp.class;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notice I do the proc sort PRIOR to dividing the datasets - no need to sort each result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now the above is a case where I know in advance the values of the sex variables.&amp;nbsp; But if I didn't know them in advance, then:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select distinct cats("test_",sex,"(where=(sex='",sex,"'))")
  into :dslist separated by ' ' &lt;BR /&gt;  from have;
quit;
%put &amp;amp;=dslist;

data &amp;amp;dslist ;
  set sashelp.class;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The strategy is to use the "&lt;EM&gt;&lt;STRONG&gt;INTO :&lt;/STRONG&gt;&lt;/EM&gt;" clause in proc sql to create a macrovars.&amp;nbsp; The (visually) tricky part is the cats function.&amp;nbsp; Segment it to look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cats("test_"
    ,sex
    ,"(where=(sex='"
    ,sex
    ,"'))"
    )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The "%put &amp;amp;=dslist;" statement shows what macrovar was generated.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 07:58:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713665#M220205</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-01-24T07:58:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract all values from a variable and use it to subset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713670#M220210</link>
      <description>&lt;P&gt;Why would you want to create hundreds of tables when you have everything in one place?&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 08:34:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713670#M220210</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-01-24T08:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract all values from a variable and use it to subset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713677#M220213</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/111564"&gt;@HitmonTran&lt;/a&gt;&amp;nbsp;This can be achieve by macro. you can try below code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	length subject 8. aeterm $200.;
	input SUBJECT AETERM $;
	cards;
 1 headache
 1 fever
 2 headache
 2 fatigue
 2 cough
 2 sneeze
 ;
run;

proc sql noprint;
	select distinct(aeterm) into :aeterm1- from have;
	%let c=&amp;amp;SQLOBS;
quit;

%macro aeterm_table;
	%do i=1 %to &amp;amp;c.;

		proc sort data=have out=test&amp;amp;i;
			by subject;
			where aeterm eq "&amp;amp;&amp;amp;aeterm&amp;amp;i";
	%end;
%mend;

%aeterm_table;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Jan 2021 14:08:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713677#M220213</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2021-01-24T14:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract all values from a variable and use it to subset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713695#M220220</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Anything&lt;/STRONG&gt; you can do with gaggle of data sets can be done with the single data set and your where condition. So there is really seldom a legitimate reason to create a bunch of data sets.&lt;/P&gt;
&lt;P&gt;Plus the way your example works how do you keep track of the data set by value? If I see data set Test1 there is nothing telling me that the values with be "headache". And spelling can raise it's ugly head. "Headache" is not the same as "headache" is not the same as "HEADACHE".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I want to perform analysis on those values such as a regression:&lt;/P&gt;
&lt;PRE&gt;Proc reg data=test;
   where upcase(aeterm)= 'HEADACHE';
&amp;lt;other regression statements&amp;gt;
&lt;/PRE&gt;
&lt;P&gt;Another consideration is that what if you want to use two of these values in a single procedure? Now you have to take a separate step to recombine the data. But you can select multiple values:&lt;/P&gt;
&lt;PRE&gt;Proc sgplot data=test;
   where upcase(aeterm) in ('HEADACHE' 'FEVER');
   scatter x=height y=weight/ group=aeterm;
run;&lt;/PRE&gt;
&lt;P&gt;for example to create grouped plot based on values of aeterm.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 16:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713695#M220220</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-24T16:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract all values from a variable and use it to subset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713700#M220221</link>
      <description>Indeed, this might be a classic case of improper design. What is the final goal there? When that is formulated then a simple solution can be found, most likely without splitting your data set into many.</description>
      <pubDate>Sun, 24 Jan 2021 16:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713700#M220221</guid>
      <dc:creator>LeonidBatkhan</dc:creator>
      <dc:date>2021-01-24T16:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract all values from a variable and use it to subset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713709#M220224</link>
      <description>The Goal is to collect all AETERM, calulate the 95% CI, then merge each AETERM's 95% CI back to the the AETERM along with other variables that were calculated earlier (eg. # of Events, # of subjects experience the event)</description>
      <pubDate>Sun, 24 Jan 2021 18:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713709#M220224</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2021-01-24T18:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract all values from a variable and use it to subset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713725#M220233</link>
      <description>hey Singh is there a typo in proq sql step ("aeterm1-")?&lt;BR /&gt;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select distinct(aeterm) into :aeterm1- from have;&lt;BR /&gt;%let c=&amp;amp;SQLOBS;&lt;BR /&gt;quit;</description>
      <pubDate>Sun, 24 Jan 2021 19:09:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713725#M220233</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2021-01-24T19:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract all values from a variable and use it to subset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713767#M220247</link>
      <description>&lt;P&gt;Please show the code you use for calculating the CI for a single AETERM.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 22:04:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713767#M220247</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-24T22:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract all values from a variable and use it to subset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713786#M220265</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/111564"&gt;@HitmonTran&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;The Goal is to collect all AETERM, calulate the 95% CI, then merge each AETERM's 95% CI back to the the AETERM along with other variables that were calculated earlier (eg. # of Events, # of subjects experience the event)&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since your Aeterm variable values shown are all character I have to assume that you meant the confidence interval of another variable that is actually numeric. &lt;/P&gt;
&lt;P&gt;Here is an example getting multiple statistics, including upper and lower confidence limits of multiple numeric variables for each level of a character (or numeric) variable.&lt;/P&gt;
&lt;PRE&gt;proc summary data=sashelp.class nway;
   class sex;
   var height weight;
   output out=work.summary 
     min= mean= max= lclm= uclm= /autoname;
run;&lt;/PRE&gt;
&lt;P&gt;For each level of Sex there will be min, mean, max, lower confidence limit for the mean, upper confidence limit for the mea of each variable on the VAR statement.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2021 00:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713786#M220265</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-25T00:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to extract all values from a variable and use it to subset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713884#M220314</link>
      <description>It's not a typo error. it's way of creating multiple macro variable without passing upper limit value.&lt;BR /&gt;</description>
      <pubDate>Mon, 25 Jan 2021 12:33:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-extract-all-values-from-a-variable-and-use-it-to-subset/m-p/713884#M220314</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2021-01-25T12:33:12Z</dc:date>
    </item>
  </channel>
</rss>

