<?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: Create new variable names from a list of values from another variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890655#M351927</link>
    <description>Oh wow! So simple :O. Thank you so much for your help and explanation!</description>
    <pubDate>Wed, 23 Aug 2023 20:08:09 GMT</pubDate>
    <dc:creator>ANKH1</dc:creator>
    <dc:date>2023-08-23T20:08:09Z</dc:date>
    <item>
      <title>Create new variable names from a list of values from another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890633#M351921</link>
      <description>&lt;P&gt;If you have a table generated in SAS by proc freq such as:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;age&lt;/TD&gt;&lt;TD&gt;frequency&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;22&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;How do you create a list of variables based on all the values of age, new variables: age_1, age_4, age_6, age_11, age_12?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2023 18:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890633#M351921</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-08-23T18:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable names from a list of values from another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890637#M351922</link>
      <description>&lt;P&gt;Best to leave the data in long format, where SAS can treat it like data. As soon as you put the age number into a variable name, you are making your programming more difficult. What do you anticipate is the next step with this data, if you did transform it?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2023 19:00:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890637#M351922</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-23T19:00:27Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable names from a list of values from another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890648#M351923</link>
      <description>&lt;P&gt;Thank you for your answer. This is a sample of the dataset we are initially working with:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;age&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;131&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;22&lt;/TD&gt;&l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gt;2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ultimately we want a table that counts IDS with at least one form by age. IDs that have more than one count for the same age, can only be accounted once. Like ID1 that has two counts for age =0 but it only adds one to the total of IDs.&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Age&lt;/TD&gt;&lt;TD&gt;Count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;22&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;48&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;76&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;131&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 23 Aug 2023 19:28:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890648#M351923</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-08-23T19:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable names from a list of values from another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890649#M351924</link>
      <description>&lt;P&gt;If you want a table or report, instead of a SAS data set, you don't need to convert the SAS data set to horizontal. You can use PROC REPORT without converting the data set to horizontal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it's really not clear to me the final table is going to look like. It seems as if you want the final table to be vertical, which isn't what was implied earlier. And it seems as if you are treating age as a discrete set of values, they can only be 0, 3, 22, 48, 131 (?), is that really a good assumption?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2023 19:44:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890649#M351924</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-23T19:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable names from a list of values from another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890652#M351925</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226521"&gt;@ANKH1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your ultimate result table can be obtained directly from your input table with a small SQL select. The detour over Proc Freq is quite unnessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID age;
  cards;
1	131
1	0
1	0
2	22
2	76
3	0
3	48
3	48
3	3
;
run;

proc sql;
  create table want as
    select age, count(age) as Count
    from (select distinct ID, age from have)
    group by age;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="agecount.gif" style="width: 222px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/86967i11AECA8A120CAD82/image-size/large?v=v2&amp;amp;px=999" role="button" title="agecount.gif" alt="agecount.gif" /&gt;&lt;/span&gt;&lt;/P&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The subselect removes duplicates, and the main select counts occurrences per age.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2023 19:56:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890652#M351925</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2023-08-23T19:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable names from a list of values from another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890653#M351926</link>
      <description>&lt;P&gt;It will be great to use proc report. We don't need to create sas dataset. Although the output might be used to create figures.&lt;/P&gt;&lt;P&gt;The final output table was depicted in a vertical way but there is no preference, as long as the results are the same. Age values vary across datasets. Some datasets have age values 0,3,22,48, etc. some other might have 1,22,56,131, etc.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2023 20:00:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890653#M351926</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-08-23T20:00:38Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable names from a list of values from another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890655#M351927</link>
      <description>Oh wow! So simple :O. Thank you so much for your help and explanation!</description>
      <pubDate>Wed, 23 Aug 2023 20:08:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890655#M351927</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-08-23T20:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable names from a list of values from another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890657#M351928</link>
      <description>&lt;P&gt;If I might ask, going back to another question I had posted before, I've realized that by converting my data into wide format I complicate things. Let's say you have the same data structure in the long format. But now we also need to get the cumulative number of people who had an incident up until every age. The tricky part is that once a person has an incident and it is accounted for, if this person has incidents after that, it doesn't contribute to increasing the count anymore. Let's say for ID3 it presents an incident at age 1, 3 and 48. But this person can only contributes to the count at age 1. And also, if they have more than one incident at the same age, it counts as 1. The output should look like this:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Age&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Cumulative&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;22&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;48&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;76&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;131&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 23 Aug 2023 20:26:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890657#M351928</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-08-23T20:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable names from a list of values from another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890705#M351945</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226521"&gt;@ANKH1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry for the late answer, but I live in europe and went to bed before I received your next question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We can twist the sql select to do that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID age;
  cards;
1	131
1	0
1	0
2	22
2	76
3	0
3	48
3	48
3	3
;
run;

proc sql;
  create table want as
    select age, count(age) as Cumulative
    from (select distinct ID, min(age) as age from have group by id)
    group by age;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What happens here is that the subselect creates a distinct list with ID and minimum age,&lt;/P&gt;
&lt;P&gt;and the outer select counts occurences of minumum age.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="minagegroup.png" style="width: 235px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/86990i5528BBB84ABA1E34/image-size/large?v=v2&amp;amp;px=999" role="button" title="minagegroup.png" alt="minagegroup.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2023 08:17:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890705#M351945</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2023-08-24T08:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable names from a list of values from another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890707#M351947</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226521"&gt;@ANKH1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry, I misunderstood the "cumulative" part. I have just read your other post, and the answer from&amp;nbsp;@andreas_lds seems to solve your problem.&lt;/P&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>Thu, 24 Aug 2023 08:48:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890707#M351947</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2023-08-24T08:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable names from a list of values from another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890758#M351975</link>
      <description>Thank you looking at my question after! I really appreciate it.</description>
      <pubDate>Thu, 24 Aug 2023 13:59:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-names-from-a-list-of-values-from-another/m-p/890758#M351975</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-08-24T13:59:14Z</dc:date>
    </item>
  </channel>
</rss>

