<?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 Adding States to Dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-States-to-Dataset/m-p/688005#M208925</link>
    <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset of degree programs and am trying to setup a dataset to manipulate into visualizations on Tableau. In order to get the data where I want it, I need to add a state variable and each of the 47 programs need to have all 50 US states listed for it (2,350 rows).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to add these in quickly with a SAS program so that I don't have to do this manually in Excel?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 20:48:50 GMT</pubDate>
    <dc:creator>dpachorek</dc:creator>
    <dc:date>2020-09-30T20:48:50Z</dc:date>
    <item>
      <title>Adding States to Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-States-to-Dataset/m-p/688005#M208925</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset of degree programs and am trying to setup a dataset to manipulate into visualizations on Tableau. In order to get the data where I want it, I need to add a state variable and each of the 47 programs need to have all 50 US states listed for it (2,350 rows).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to add these in quickly with a SAS program so that I don't have to do this manually in Excel?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 20:48:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-States-to-Dataset/m-p/688005#M208925</guid>
      <dc:creator>dpachorek</dc:creator>
      <dc:date>2020-09-30T20:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Adding States to Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-States-to-Dataset/m-p/688009#M208928</link>
      <description>Check the SASHELP or SASMAPS library for the State level datasets you can merge (left join) your results with to get the data you need. &lt;BR /&gt;&lt;BR /&gt;Depending on exactly what you're doing you may also want to look into CLASSDATA or PRELOADFMT. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Sep 2020 20:56:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-States-to-Dataset/m-p/688009#M208928</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-09-30T20:56:22Z</dc:date>
    </item>
    <item>
      <title>Re: Adding States to Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-States-to-Dataset/m-p/688018#M208933</link>
      <description>&lt;P&gt;So, you have a dataset containing information on 47 degree programs.&amp;nbsp; You need to add all 50 states to each degree.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think just taking the Cartesian product via SQL should do it pretty simply and easily.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this, although you'd have to use real state codes or state names and real degree names.&amp;nbsp; I just used dummy names, but the SQL should be essentially the same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data	Degrees;
	drop	_:;
	DO	_I	=	1	TO	47;
		Degree_name	= CATS('Degree', put(_i, 2.));
		OUTPUT;
	END;
run;

DATA	States;
	drop	_:;
	DO	_I	=	1	TO	50;
		State_Code	= CATS('State', put(_i, 2.));
		OUTPUT;
	END;
run;

PROC	SQL;
	CREATE TABLE	Degrees_With_States	AS
		SELECT	Degree_Name
				,State_Code
			from	degrees, states;	
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Sep 2020 21:08:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-States-to-Dataset/m-p/688018#M208933</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-30T21:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: Adding States to Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-States-to-Dataset/m-p/688030#M208939</link>
      <description>&lt;P&gt;Excellent Idea from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;.&amp;nbsp; My solution is the same:&amp;nbsp; Use SQL to create the Cartesian product, but the State table can be fairly easily created from SAShelp.GCstate.&amp;nbsp; GCstate includes territories like GU, PR, VI, etc. and Washington DC ("DC"), but you can screen out the ones you don't want fairly easily.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code changed as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data	Degrees;
	drop	_:;
	DO	_I	=	1	TO	47;
		Degree_name	= CATS('Degree', put(_i, 2.));
		OUTPUT;
	END;
run;

/*DATA	States;*/
/*	drop	_:;*/
/*	DO	_I	=	1	TO	50;*/
/*		State_Code	= CATS('State', put(_i, 2.));*/
/*		OUTPUT;*/
/*	END;*/
/*run;*/

PROC	SQL;
	CREATE	TABLE	States	as
		SELECT	DISTINCT	MapIDNameAbrv	as	State_Code
			FROM	SAShelp.GCSTATE
				WHERE	ISOalpha3	=	'USA';
QUIT;

PROC	SQL;
	CREATE TABLE	Degrees_With_States	AS
		SELECT	Degree_Name
				,State_Code
			from	degrees, states;	
QUIT;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 21:21:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-States-to-Dataset/m-p/688030#M208939</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-30T21:21:01Z</dc:date>
    </item>
  </channel>
</rss>

