<?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 do I create many variables from an existing variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-many-variables-from-an-existing-variable/m-p/611405#M178181</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

Data Have;
input id $ location $6. date MONYY6.;
format date monyy6.;
datalines;
1 Type_A Nov05
2 Type_B Dec05
3 Type_C Jan06
4 Type_B Nov05
5 Type_A Nov05
6 Type_B Jan06
;
proc sql noprint;
select put( date,monyy6.) into :list separated by ' ' 
from (select distinct date from have);
quit;
%put &amp;amp;=list &amp;amp;=sqlobs;

data want;
set have;
array t(*) &amp;amp;list;
array tt(9999)$32 _temporary_;
retain tt;
if _n_=1 then do;
 do _n_=1 to dim(t);
  tt(_n_)=vname(t(_n_));
 end;
end;
 do _n_=1 to dim(t);
  t(_n_)=0;
 end;
k=whichc(put(date,monyy6. -l),of tt(*));
if k then t(k)=1;
drop k;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 12 Dec 2019 17:36:28 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-12-12T17:36:28Z</dc:date>
    <item>
      <title>How do I create many variables from an existing variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-many-variables-from-an-existing-variable/m-p/611391#M178178</link>
      <description>&lt;P&gt;Hello all, I have a data set of individuals and when they leave a location. I am trying to find the flow of people by month. My data set is like the code below but instead I have some 11,500 entries and exits over the course of 120 months for 3 types of locations.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
input id $ location $6. date MONYY6.;
datalines;

1 Type_A Nov05
2 Type_B Dec05
3 Type_C Jan06
4 Type_B Nov05
5 Type_A Nov05
6 Type_B Jan06
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So. I would like to create a variable for each month so that I can sum the flow from each location type. The data set would look something like the following.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Want;
input id $ location $6. date MONYY6. Nov05 $ Dec05 $ Jan06 $;
datalines;

1 Type_A Nov05 1 0 0
2 Type_B Dec06 0 1 0
3 Type_C Jan01 0 0 1
4 Type_B Nov05 1 0 0
5 Type_A Nov05 1 0 0
6 Type_B Jan01 0 0 1
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 17:00:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-many-variables-from-an-existing-variable/m-p/611391#M178178</guid>
      <dc:creator>JDDowell</dc:creator>
      <dc:date>2019-12-12T17:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create many variables from an existing variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-many-variables-from-an-existing-variable/m-p/611405#M178181</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

Data Have;
input id $ location $6. date MONYY6.;
format date monyy6.;
datalines;
1 Type_A Nov05
2 Type_B Dec05
3 Type_C Jan06
4 Type_B Nov05
5 Type_A Nov05
6 Type_B Jan06
;
proc sql noprint;
select put( date,monyy6.) into :list separated by ' ' 
from (select distinct date from have);
quit;
%put &amp;amp;=list &amp;amp;=sqlobs;

data want;
set have;
array t(*) &amp;amp;list;
array tt(9999)$32 _temporary_;
retain tt;
if _n_=1 then do;
 do _n_=1 to dim(t);
  tt(_n_)=vname(t(_n_));
 end;
end;
 do _n_=1 to dim(t);
  t(_n_)=0;
 end;
k=whichc(put(date,monyy6. -l),of tt(*));
if k then t(k)=1;
drop k;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Dec 2019 17:36:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-many-variables-from-an-existing-variable/m-p/611405#M178181</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-12T17:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create many variables from an existing variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-many-variables-from-an-existing-variable/m-p/611408#M178182</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/285214"&gt;@JDDowell&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;So. I would like to create a variable for each month so that I can sum the flow from each location type. The data set would look something like the following.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sums by some sort of group do not require these 0/1 variables. It can be done very easily in PROC SUMMARY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show us the real input and final desired output rather than this unnecessary intermediate step of creating zero/one variables.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 17:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-many-variables-from-an-existing-variable/m-p/611408#M178182</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-12T17:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create many variables from an existing variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-many-variables-from-an-existing-variable/m-p/611421#M178186</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/285214"&gt;@JDDowell&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no need to create dummy variables to do that.&lt;/P&gt;
&lt;P&gt;You can try the following code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
	tables date*location / out=want nocum nopercent norow nocol;
	format date MONYY6.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Dec 2019 19:00:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-many-variables-from-an-existing-variable/m-p/611421#M178186</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-12-12T19:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create many variables from an existing variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-many-variables-from-an-existing-variable/m-p/611634#M178290</link>
      <description>&lt;P&gt;I can't share real input because of the information contained within it, could you be more specific as to what you are wanting? The only real difference would be that my dates have days, they're not really all lumped into a month, I've only formatted them that way. I think for that reason that if I did a proc summary by date, they would sum for each individual date.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 16:17:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-many-variables-from-an-existing-variable/m-p/611634#M178290</guid>
      <dc:creator>JDDowell</dc:creator>
      <dc:date>2019-12-13T16:17:35Z</dc:date>
    </item>
  </channel>
</rss>

