<?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: selecting specific values from  a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/866975#M342398</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/168930"&gt;@Anita_n&lt;/a&gt;&amp;nbsp;This code goes through all variables with the prefix 'var' and sets the value to ' ' when the original value is 'Y'.&lt;/P&gt;</description>
    <pubDate>Wed, 29 Mar 2023 13:20:33 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2023-03-29T13:20:33Z</dc:date>
    <item>
      <title>selecting specific values from  a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/866968#M342395</link>
      <description>&lt;P&gt;Dear all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if I have a dataset that looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines;
	input var1 $ var2 $ var3 $ var4 $ ;
	datalines;
Y  Y  N  N 
N  Y  N  Y
N  N  N  N
N  Y  Y  Y
N  Y  N  Y
Y  Y  Y  Y&lt;BR /&gt;
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want to select only the N values of each var. Can anyone help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is how the result should look like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	infile datalines truncover;
	input var1 $ var2 $ var3 $ var4 $ ;
	datalines;
      N  N
N     N   
N  N  N  N
N         
N     N   
          
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 13:00:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/866968#M342395</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2023-03-29T13:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: selecting specific values from  a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/866972#M342396</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines;
	input var1 $ var2 $ var3 $ var4 $ ;
	datalines;
Y  Y  N  N 
N  Y  N  Y
N  N  N  N
N  Y  Y  Y
N  Y  N  Y
Y  Y  Y  Y
;
run;

data want;
   set have;
   array v var:;
   do over v;
      if v = 'Y' then v = '';
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;var1  var2  var3  var4
            N     N
N           N 
N     N     N     N
N   
N           N 

&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Mar 2023 13:05:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/866972#M342396</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2023-03-29T13:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: selecting specific values from  a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/866974#M342397</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;, thanks for the quick reply. I have a question does this select all variables whose corresponding to values of N or does this just delect the value Y.&amp;nbsp; I want to know this because I have over 1000 variables in the dataset and I just need only the values of all variables having var1-var4 = N&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 13:18:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/866974#M342397</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2023-03-29T13:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: selecting specific values from  a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/866975#M342398</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/168930"&gt;@Anita_n&lt;/a&gt;&amp;nbsp;This code goes through all variables with the prefix 'var' and sets the value to ' ' when the original value is 'Y'.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 13:20:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/866975#M342398</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2023-03-29T13:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: selecting specific values from  a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/866979#M342399</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;okay, I tested that and realise it just delects Y but I want it to select N and its corresponding values like for example if this were to be my data have&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines;
	input var1 $ num1 var2 $ num2 var3 $ num3 var4 $  num4;
	datalines;
Y 1 Y 7 N 1 N 8
N 2 Y 2 N 2 Y 7
N 3 N 1 N 5 N 6
N 4 Y 2 Y 5 Y 7
N 5 Y 3 N 4 Y 4
Y 6 Y 4 Y 3 Y 9
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My data want should be like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	infile datalines truncover;
	input var1 $ num1 var2 $ num2 var3 $ num3 var4 $  num4;
	datalines;
        N 1 N 8
N 2     N 2    
N 3 N 1 N 5 N 6
N 4            
N 5     N 4    
               
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;ed&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 13:37:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/866979#M342399</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2023-03-29T13:37:30Z</dc:date>
    </item>
    <item>
      <title>Re: selecting specific values from  a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/867016#M342411</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/168930"&gt;@Anita_n&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;okay, I tested that and realise it just delects Y but I want it to select N and its corresponding values like for example if this were to be my data have&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If a variable is in a SAS data set at all then there will be a value for it, which means missing with what you show for a "want".&lt;/P&gt;
&lt;P&gt;The variable exists so is must have something.&lt;/P&gt;
&lt;P&gt;It is much easier to set to missing for the unwanted than to attempt to "keep" the desired values.&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   array v (*)  var1- var4;
   array nn (*)  num1- num4;
   do i=1 to dim(v);
      if v[i]='Y' then call missing(v[i],nn[i]);
   end;
   drop i;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 14:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/867016#M342411</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-29T14:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: selecting specific values from  a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/867041#M342415</link>
      <description>&lt;P&gt;Is there no way to do that using proc sql. I don't know if arrays can be used in proc sql. I know using OR or AND doesn't work but aybe there is a specific way doing that&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as select * from have where var1="N" or var2="N" or var3="N" and var4="N";
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 14:53:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/867041#M342415</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2023-03-29T14:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: selecting specific values from  a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/867052#M342418</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/168930"&gt;@Anita_n&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is there no way to do that using proc sql. I don't know if arrays can be used in proc sql. I know using OR or AND doesn't work but aybe there is a specific way doing that&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as select * from have where var1="N" or var2="N" or var3="N" and var4="N";
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SQL does not support arrays.&lt;/P&gt;
&lt;P&gt;You would need to write 8 Case statements, one for each variable involved, testing the Var variable to set the value of the Num variable.&lt;/P&gt;
&lt;P&gt;If you had a nice variable for Joining on you might get away with 4 bits like (select id, var1,num1 from set where Var1='N').&lt;/P&gt;
&lt;P&gt;Multiple variables requiring similar treatment easily is not an SQL strength.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 15:24:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/867052#M342418</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-29T15:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: selecting specific values from  a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/867057#M342419</link>
      <description>&lt;P&gt;okay, thankyou&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 15:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/867057#M342419</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2023-03-29T15:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: selecting specific values from  a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/867190#M342472</link>
      <description>&lt;P&gt;May I ask what the actual application is?&lt;/P&gt;
&lt;P&gt;I hope that the real data has som kind of row identifier.&lt;/P&gt;
&lt;P&gt;If, so you could transpose the data, and then jsut do the transformation on one column, or just add a format that hides the "Y"&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 08:14:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/867190#M342472</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2023-03-30T08:14:31Z</dc:date>
    </item>
    <item>
      <title>Re: selecting specific values from  a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/867228#M342495</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt;&amp;nbsp;Is all about patients who received certain treatments on each visit (let's say visits 1 to 10),&amp;nbsp; But there a certain patients who took part in a clinical trial who should be excluded from this project. Now for each visit there is a variable which indicate if they took part in a clinical trial at that specific visit (if yes then the variable= Y and if no then it's =N)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That was what I tried to depict above with var1 to var4 . Now I need to select all patients who did not take take in a clinical trial for all visits 1 to 10&amp;nbsp; (that means var1 to var10 has to be N, there shouldn't be any Y's&amp;nbsp; in the dataset)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All this selection should include all data of the patients like the id, age, sex, diagnosis date, deathdate, type of treatment etc.....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did this with sas macro that looks like this and later merged them:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test (num);
proc sql,
create table want&amp;amp;num as select id, therapy&amp;amp;num, visit&amp;amp;num, clintrial&amp;amp;num where clintrial&amp;amp;num="N";
quit;
%mend;
%test(1); %test(2); %test(3); %test(4); %test(5);%test(6); %test(7); %test(8); %test(9); %test(10);&lt;BR /&gt;&lt;BR /&gt;*merge all 10 datasets;&lt;BR /&gt;data&amp;nbsp;want,&lt;BR /&gt;merge&amp;nbsp;want:;&lt;BR /&gt;by&amp;nbsp;id;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My problem here is I can't select all variables, since if I do that&amp;nbsp; for test1 for example then I will have test2 to test10 with&amp;nbsp; undesired values in there. So I was thinking there is a better way doing that. But it seems to be complicated&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 11:27:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/867228#M342495</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2023-03-30T11:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: selecting specific values from  a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/867234#M342496</link>
      <description>&lt;P&gt;Not sure if removing the value "Y" will help you with this logic (if understand your use case correcrtly).&lt;/P&gt;
&lt;P&gt;If your flags were 0/1 instead a simple&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; if sum(of var1-var10) = 0 then delete;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;suffice.&lt;/P&gt;
&lt;P&gt;I guess array as described earlier in the thread is a valid way of doing it, but just add some logic to delete the record if all elements are "N".&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 12:05:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-specific-values-from-a-dataset/m-p/867234#M342496</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2023-03-30T12:05:10Z</dc:date>
    </item>
  </channel>
</rss>

