<?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: Using the value of a variable to make and name new variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595787#M15850</link>
    <description>&lt;P&gt;Ah! I was not familiar with the id statement used in proc transpose like this. This would be a lot simpler. Thank you!&lt;/P&gt;</description>
    <pubDate>Fri, 11 Oct 2019 15:41:31 GMT</pubDate>
    <dc:creator>solfay243</dc:creator>
    <dc:date>2019-10-11T15:41:31Z</dc:date>
    <item>
      <title>Using the value of a variable to make and name new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595776#M15845</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've got a dataset with a bunch of values in a column, but I'd like to make variable in a new dataset named after those values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example what I have is:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input $ names;
datalines;
A
B
C
D
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And what I'd like for my end result is:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input $ A $ B $ C $ D;
datalines;
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I suppose I could use an array to grab all the values and make them variables with a do loop, but I wanted to see if anyone else had other thoughts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 15:29:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595776#M15845</guid>
      <dc:creator>solfay243</dc:creator>
      <dc:date>2019-10-11T15:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a variable to make and name new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595777#M15846</link>
      <description>&lt;P&gt;did you try PROC TRANSPOSE?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 15:29:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595777#M15846</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-11T15:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a variable to make and name new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595778#M15847</link>
      <description>&lt;P&gt;This isn't quite the same as I'm not looking to shift the form of the data from long to wide, but I'm looking to use the data's values to make new variables which are named after those values.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 15:30:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595778#M15847</guid>
      <dc:creator>solfay243</dc:creator>
      <dc:date>2019-10-11T15:30:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a variable to make and name new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595785#M15848</link>
      <description>&lt;P&gt;I am not sure If i am understanding your requirement. However, looking at your HAVE and WANT seems like a Transpose like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input  names $;
datalines;
A
B
C
D
;
run;

proc transpose data=have out=w(drop=_name_);
id names;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;NOTE: No variables to transpose.&lt;BR /&gt;NOTE: There were 4 observations read from the data set WORK.HAVE.&lt;BR /&gt;NOTE: The data set WORK.W has 0 observations and 4 variables.&lt;BR /&gt;NOTE: PROCEDURE TRANSPOSE used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 15:39:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595785#M15848</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-11T15:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a variable to make and name new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595786#M15849</link>
      <description>&lt;P&gt;Can you explain the use case or logic behind this?&lt;BR /&gt;SAS variables are not created as easily on the fly so you're likely diving into macros or arrays here at minimum.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically, it's possible to do this but it's cumbersome and tedious and there are usually many alternative ways to get a similar functionality that's easier, if you explain your use case/logic.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://en.wikipedia.org/wiki/XY_problem" target="_blank"&gt;https://en.wikipedia.org/wiki/XY_problem&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 15:41:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595786#M15849</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-11T15:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a variable to make and name new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595787#M15850</link>
      <description>&lt;P&gt;Ah! I was not familiar with the id statement used in proc transpose like this. This would be a lot simpler. Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 15:41:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595787#M15850</guid>
      <dc:creator>solfay243</dc:creator>
      <dc:date>2019-10-11T15:41:31Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a variable to make and name new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595788#M15851</link>
      <description>&lt;P&gt;First, test your steps before posting here. Yours cause ERRORs.&lt;/P&gt;
&lt;P&gt;Second, transpose is the way to go:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input names $;
datalines;
A
B
C
D
;
run;

proc transpose data=have out=trans (drop=_name_);
var names;
id names;
run;

data want;
set trans;
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Oct 2019 15:42:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595788#M15851</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-11T15:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a variable to make and name new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595789#M15852</link>
      <description>&lt;P&gt;You apparently want to read in raw data, with the desired variables for each record arranged in a column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the variables are arranged the same way for every observation (i.e. 5 lines of data for each obs), then use "line pointer controls" such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&amp;nbsp;/&amp;nbsp;&amp;nbsp;&amp;nbsp; which tells SAS to advance one data line&lt;/LI&gt;
&lt;LI&gt;#n&amp;nbsp;&amp;nbsp; which tells SAS to advance to the n'th line in a group&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, crudely speaking, you could&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   input x1   /   x2 x3   / x4;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which tells SAS to expect 3 lines for each observations, with variable X1 on the first line,&amp;nbsp;&amp;nbsp; X2 and X3 on the 2nd line, and X4 on the third line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this is not a correct interpretation of your problem, please show actual data as you have it, and actual data layout as you want it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 15:44:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595789#M15852</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-10-11T15:44:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a variable to make and name new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595790#M15853</link>
      <description>&lt;P&gt;Heh. I would not have expected that transpose tolerates 'no var statement' without at least a WARNING.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 15:45:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595790#M15853</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-11T15:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a variable to make and name new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595792#M15854</link>
      <description>&lt;P&gt;I am going into making a large macro. The end product is an input control file for use in a macro itself to create a baseline dataset to describe a cohort.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is just a step in the process of that for me. I'm first creating a dataset of the files from a directory (multiple directories eventually) and then creating flag indicators of the file names themselves and eventually doing some analysis throughout all of those datasets. It's a long procedure so I tried to keep this question simple and was just looking at how others may strategize this step apart from what I was already aware of.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 15:46:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595792#M15854</guid>
      <dc:creator>solfay243</dc:creator>
      <dc:date>2019-10-11T15:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a variable to make and name new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595797#M15855</link>
      <description>SAS BY group and CLASS statements usually mean you don't need to dummy code your own variables. And even if you do need to create dummy codes, glmselect can help automate that.</description>
      <pubDate>Fri, 11 Oct 2019 15:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595797#M15855</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-11T15:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a variable to make and name new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595804#M15858</link>
      <description>&lt;P&gt;Sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; I learned these plus (obs=0) in transposing variable names&amp;nbsp; from the notes I have taken from excerpts of&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;(as we know him as PRODIGYGENIUSstats) and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp; a while ago.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a matter of fact, PG once showed how to use how to copy just metadata and create a new table using LIKE operator in a peculiar way&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Like operator to copy metadata*/
proc sql;
create table want
like sashelp.class;
quit;

proc contents data=want;
run;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 16:06:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595804#M15858</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-11T16:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a variable to make and name new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595807#M15860</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;To output 0 obs you can use where=false;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;199  proc transpose data=have out=trans(where=(0) drop=_name_);
200  var names;
201  id names;
202  run;

NOTE: There were 4 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.TRANS has 0 observations and 4 variables.
&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Oct 2019 16:24:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595807#M15860</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2019-10-11T16:24:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a variable to make and name new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595821#M15861</link>
      <description>&lt;P&gt;That is not the LIKE operator.&amp;nbsp; It is a different syntax that just happened to use the same name as the LIKE operator.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 17:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595821#M15861</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-11T17:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a variable to make and name new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595824#M15863</link>
      <description>&lt;P&gt;Per SAS vocabulary, it is a &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=n1cq72kb6ab41in1pzngij4dhek1.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;SQL procedure component&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 17:04:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595824#M15863</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-11T17:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a variable to make and name new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595828#M15864</link>
      <description>&lt;P&gt;Ah ok. Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 17:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-the-value-of-a-variable-to-make-and-name-new-variables/m-p/595828#M15864</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-11T17:12:59Z</dc:date>
    </item>
  </channel>
</rss>

