<?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: copy specific value for each city in new var in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/copy-specific-value-for-each-city-in-new-var/m-p/758752#M239649</link>
    <description>&lt;P&gt;Great, thank you! Do you have a further minute for writing a short description what your sql-commands exactly do? What for example means the "a.*" (a.city, a.quarter,...)? I want to learn it and need to get some hinks...&lt;/P&gt;</description>
    <pubDate>Mon, 02 Aug 2021 11:42:24 GMT</pubDate>
    <dc:creator>Konkordanz</dc:creator>
    <dc:date>2021-08-02T11:42:24Z</dc:date>
    <item>
      <title>copy specific value for each city in new var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/copy-specific-value-for-each-city-in-new-var/m-p/758742#M239640</link>
      <description>&lt;P&gt;Hi forum,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset with &amp;gt;400 cities. Each city has population-values for all quarters of 2 years (Q1 2019, Q2 2019, ..., Q4 2020). I want to create a new variable (pop_q4_2020) with the values of Q4 2020 of the respecitve city. Thats what I have:&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;
input city $ year quarter population;
datalines;
CityA 2019 3 20029
CityB 2019 2 34900
CityA 2020 2 19853
CityB 2020 2 34500
CityA 2019 2 20029
CityA 2020 4 19853
CityB 2020 4 34300
CityA 2019 4 20029
CityB 2019 3 34800
CityB 2020 1 34600&lt;BR /&gt;CityA 2019 1 20135&lt;BR /&gt;CityA 2020 3 19853
CityB 2020 3 34400
CityB 2019 4 34700
CityA 2020 1 20029
CityB 2019 1 35000
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thats what I want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 240pt;" border="0" width="320" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="80" height="16" class="xl66" style="height: 12.0pt; width: 60pt;"&gt;&lt;STRONG&gt;Region&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="80" class="xl66" style="width: 60pt;"&gt;&lt;STRONG&gt;year&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="80" class="xl66" style="width: 60pt;"&gt;&lt;STRONG&gt;quarter&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="80" class="xl66" style="width: 60pt;"&gt;&lt;STRONG&gt;pop_q4_2020&lt;BR /&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;CityA&lt;/TD&gt;
&lt;TD align="right"&gt;2019&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;TD align="right"&gt;19853&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;CityB&lt;/TD&gt;
&lt;TD align="right"&gt;2019&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;34300&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;CityA&lt;/TD&gt;
&lt;TD align="right"&gt;2020&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;19853&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;CityB&lt;/TD&gt;
&lt;TD align="right"&gt;2020&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;34300&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;CityA&lt;/TD&gt;
&lt;TD align="right"&gt;2019&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;19853&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;CityA&lt;/TD&gt;
&lt;TD align="right"&gt;2020&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;TD align="right"&gt;19853&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;CityB&lt;/TD&gt;
&lt;TD align="right"&gt;2020&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;TD align="right"&gt;34300&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;CityA&lt;/TD&gt;
&lt;TD align="right"&gt;2019&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;TD align="right"&gt;19853&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;CityB&lt;/TD&gt;
&lt;TD align="right"&gt;2019&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;TD align="right"&gt;34300&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;CityB&lt;/TD&gt;
&lt;TD align="right"&gt;2020&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;34300&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;CityA&lt;/TD&gt;
&lt;TD align="right"&gt;2019&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;19853&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;CityA&lt;/TD&gt;
&lt;TD align="right"&gt;2020&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;TD align="right"&gt;19853&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;CityB&lt;/TD&gt;
&lt;TD align="right"&gt;2020&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;TD align="right"&gt;34300&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;CityB&lt;/TD&gt;
&lt;TD align="right"&gt;2019&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;TD align="right"&gt;34300&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;CityA&lt;/TD&gt;
&lt;TD align="right"&gt;2020&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;19853&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;CityB&lt;/TD&gt;
&lt;TD align="right"&gt;2019&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;34300&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried it with this steps: create a new var and copy the value of population-var if year=2020 and quarter=4. But I dont know how to copy the values into the cells with the same city-names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Thank you for help!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 10:50:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/copy-specific-value-for-each-city-in-new-var/m-p/758742#M239640</guid>
      <dc:creator>Konkordanz</dc:creator>
      <dc:date>2021-08-02T10:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: copy specific value for each city in new var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/copy-specific-value-for-each-city-in-new-var/m-p/758747#M239645</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table want as select a.city,a.year,a.quarter,b.population as pop_q4_2020
        from have as a left join (select * from have where year=2020 and quarter=4) as b
        on a.city=b.city;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Aug 2021 11:29:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/copy-specific-value-for-each-city-in-new-var/m-p/758747#M239645</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-02T11:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: copy specific value for each city in new var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/copy-specific-value-for-each-city-in-new-var/m-p/758752#M239649</link>
      <description>&lt;P&gt;Great, thank you! Do you have a further minute for writing a short description what your sql-commands exactly do? What for example means the "a.*" (a.city, a.quarter,...)? I want to learn it and need to get some hinks...&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 11:42:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/copy-specific-value-for-each-city-in-new-var/m-p/758752#M239649</guid>
      <dc:creator>Konkordanz</dc:creator>
      <dc:date>2021-08-02T11:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: copy specific value for each city in new var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/copy-specific-value-for-each-city-in-new-var/m-p/758755#M239651</link>
      <description>&lt;P&gt;The PROC SQL code takes variables city, year and quarter from the data set identified as &lt;FONT face="courier new,courier"&gt;A&lt;/FONT&gt; (which is data set HAVE) and variable population (renamed to pop_q4_2020) from data set identified as &lt;FONT face="courier new,courier"&gt;B&lt;/FONT&gt;, and joins them where &lt;FONT face="courier new,courier"&gt;a.city=b.city&lt;/FONT&gt; (a left join is used, meaning the records of the data set on the left, which is &lt;FONT face="courier new,courier"&gt;A&lt;/FONT&gt;, are selected to be in the output table). Data set &lt;FONT face="courier new,courier"&gt;B&lt;/FONT&gt; is created by selecting all variables from HAVE, and all records where the year is 2020 and the quarter is 4.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 11:47:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/copy-specific-value-for-each-city-in-new-var/m-p/758755#M239651</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-02T11:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: copy specific value for each city in new var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/copy-specific-value-for-each-city-in-new-var/m-p/758984#M239746</link>
      <description>&lt;P&gt;Thx for explaination. So, can it interprated as follows? And what does the open points mean?&lt;/P&gt;
&lt;P&gt;What I doesnt understand: The code shall combine table a and table b...but isnt the column "city" only a content of the table a?&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;create table want as select a.city,a.year,a.quarter &lt;STRONG&gt;/*these var comes into the temp. table "a"*/&lt;/STRONG&gt;,
b.population as pop_q4_2020  &lt;STRONG&gt;/*this var comes into the temp table "b" and get a new name*/&lt;/STRONG&gt;
from have &lt;STRONG&gt;/*the source-table of the variables */&lt;/STRONG&gt;
as a left join (select * from have where year=2020 and quarter=4) &lt;STRONG&gt;/*all data of the table "a" with the filter year=2020 and quarter=4 shall get involved*/&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;as b &lt;STRONG&gt;/* ????*/&lt;/STRONG&gt;
on a.city=b.city; &lt;STRONG&gt;/*????*/&lt;/STRONG&gt;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Aug 2021 09:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/copy-specific-value-for-each-city-in-new-var/m-p/758984#M239746</guid>
      <dc:creator>Konkordanz</dc:creator>
      <dc:date>2021-08-03T09:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: copy specific value for each city in new var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/copy-specific-value-for-each-city-in-new-var/m-p/758998#M239755</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/388612"&gt;@Konkordanz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thx for explaination. So, can it interprated as follows? And what does the open points mean?&lt;/P&gt;
&lt;P&gt;What I doesnt understand: The code shall combine table a and table b...but isnt the column "city" only a content of the table a?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;B has all columns from HAVE, indicated by &lt;FONT face="courier new,courier"&gt;SELECT * FROM HAVE&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(select * from have where year=2020 and quarter=4) 
/*all data of the table "a" with the filter year=2020 and quarter=4 shall get involved*/
as b /* ????*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above comment in your code is incorrect. It is all the columns from data set HAVE, not table &lt;FONT face="courier new,courier"&gt;A&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Aug 2021 11:47:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/copy-specific-value-for-each-city-in-new-var/m-p/758998#M239755</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-03T11:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: copy specific value for each city in new var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/copy-specific-value-for-each-city-in-new-var/m-p/759000#M239757</link>
      <description>&lt;P&gt;"a" and "b" are &lt;EM&gt;aliases&lt;/EM&gt; for the table they are associated with. This allows you (among other things, like reducing the amount of typing) to use the same dataset several times in a query, and treat it like different datasets in the code.&lt;/P&gt;
&lt;P&gt;When you use point-and-click in the Enterprise Guide Query Builder, it will assign t1, t2, ..., tN as aliases.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Aug 2021 11:50:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/copy-specific-value-for-each-city-in-new-var/m-p/759000#M239757</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-03T11:50:32Z</dc:date>
    </item>
  </channel>
</rss>

