<?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 HELP in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/HELP/m-p/13367#M1945</link>
    <description>Suppose my dataset has variables v1 ad v2 along with other variables. The variable v1 contains date values. Suppose the record number 1 has a value of date1 and record number two also has a value of date1 and the values for the variable v2 are different for these two records. Now, I want the dataset such that there is just one record with variable v1 having the value date1 and two other variables v2 and v3. Variable v2 must contain the same value as it had for record 1. Variable v3 must have the value which variable v2 had in record 2. Can you please help me with a code for this?&lt;BR /&gt;
Example: This is how my dataset is at present.&lt;BR /&gt;
v1             v2&lt;BR /&gt;
6/2/2005    Tornado &lt;BR /&gt;
6/2/2005    Hail&lt;BR /&gt;
&lt;BR /&gt;
 &lt;BR /&gt;
 &lt;BR /&gt;
I want my dataset to be changed in following way:&lt;BR /&gt;
 &lt;BR /&gt;
v1             v2         v3&lt;BR /&gt;
6/2/2005   Tornado Hail&lt;BR /&gt;
&lt;BR /&gt;
 &lt;BR /&gt;
Above is the example of the dataset. The datset can contain same date with multiple storm conditions and not just two stotm conditions. &lt;BR /&gt;
Can you please help me how to code this?</description>
    <pubDate>Fri, 25 Apr 2008 00:11:19 GMT</pubDate>
    <dc:creator>Soha</dc:creator>
    <dc:date>2008-04-25T00:11:19Z</dc:date>
    <item>
      <title>HELP</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/HELP/m-p/13367#M1945</link>
      <description>Suppose my dataset has variables v1 ad v2 along with other variables. The variable v1 contains date values. Suppose the record number 1 has a value of date1 and record number two also has a value of date1 and the values for the variable v2 are different for these two records. Now, I want the dataset such that there is just one record with variable v1 having the value date1 and two other variables v2 and v3. Variable v2 must contain the same value as it had for record 1. Variable v3 must have the value which variable v2 had in record 2. Can you please help me with a code for this?&lt;BR /&gt;
Example: This is how my dataset is at present.&lt;BR /&gt;
v1             v2&lt;BR /&gt;
6/2/2005    Tornado &lt;BR /&gt;
6/2/2005    Hail&lt;BR /&gt;
&lt;BR /&gt;
 &lt;BR /&gt;
 &lt;BR /&gt;
I want my dataset to be changed in following way:&lt;BR /&gt;
 &lt;BR /&gt;
v1             v2         v3&lt;BR /&gt;
6/2/2005   Tornado Hail&lt;BR /&gt;
&lt;BR /&gt;
 &lt;BR /&gt;
Above is the example of the dataset. The datset can contain same date with multiple storm conditions and not just two stotm conditions. &lt;BR /&gt;
Can you please help me how to code this?</description>
      <pubDate>Fri, 25 Apr 2008 00:11:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/HELP/m-p/13367#M1945</guid>
      <dc:creator>Soha</dc:creator>
      <dc:date>2008-04-25T00:11:19Z</dc:date>
    </item>
    <item>
      <title>Re: HELP</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/HELP/m-p/13368#M1946</link>
      <description>Hi:&lt;BR /&gt;
  If you had this data:&lt;BR /&gt;
[pre]&lt;BR /&gt;
   v1        v2&lt;BR /&gt;
6/2/2005 Tornado &lt;BR /&gt;
6/2/2005 Hail&lt;BR /&gt;
6/3/2005 Rain &lt;BR /&gt;
6/3/2005 Cloudy&lt;BR /&gt;
6/4/2005 Cloudy &lt;BR /&gt;
6/5/2005 Hail&lt;BR /&gt;
6/5/2005 Tornado &lt;BR /&gt;
6/5/2005 Rain&lt;BR /&gt;
[/pre]&lt;BR /&gt;
  &lt;BR /&gt;
In a SAS dataset entitled WORK.WEATHER, then you could quite simply use the transpose procedure to change the structure of the data.&lt;BR /&gt;
[pre]&lt;BR /&gt;
     &lt;BR /&gt;
proc transpose data=work.weather out=work.w_trans;&lt;BR /&gt;
by v1;&lt;BR /&gt;
var v2;&lt;BR /&gt;
run;&lt;BR /&gt;
     &lt;BR /&gt;
options nocenter;&lt;BR /&gt;
proc print data=work.w_trans;&lt;BR /&gt;
  title 'transposed data';&lt;BR /&gt;
  format v1 mmddyy10.;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
And the results from the transpose look like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
transposed data&lt;BR /&gt;
    &lt;BR /&gt;
Obs            v1    _NAME_    COL1       COL2       COL3&lt;BR /&gt;
    &lt;BR /&gt;
 1     06/02/2005      v2      Tornado    Hail&lt;BR /&gt;
 2     06/03/2005      v2      Rain       Cloudy&lt;BR /&gt;
 3     06/04/2005      v2      Cloudy&lt;BR /&gt;
 4     06/05/2005      v2      Hail       Tornado    Rain&lt;BR /&gt;
   &lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Note that PROC TRANSPOSE, by default, calls the transposed variables "COL" and numbers the variables. If you really need to have them named differently, there are ways to rename variables or just relabel the variables to your needs. These methods are part of the fundamental concepts of how SAS stores data and you can find that information in the documentation on PROC DATASETS and/or the RENAME= dataset option. Also note that in my example data, the V1 variable is a numeric variable that represents a SAS date, so a format must be applied to show that number in its date form in the PROC PRINT step. If your V1 variable is a character string, then you would not need a Format statement.&lt;BR /&gt;
 &lt;BR /&gt;
You said that your data had "other variables" -- whether this is the right solution for you depends on what the "other" variables are and whether you need them to be part of the transposed data, too. It may be that PROC TRANSPOSE is not the right procedure for your data and you may need to look to a DATA step program to transpose the data. For more help with this task, your best bet might be to read the documentation or contact Tech Support, especially, if you are not familiar with SAS basic concepts.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Fri, 25 Apr 2008 02:08:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/HELP/m-p/13368#M1946</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-04-25T02:08:23Z</dc:date>
    </item>
    <item>
      <title>Re: HELP</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/HELP/m-p/13369#M1947</link>
      <description>a little bit long, but worth for big data set and different weather conditions.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data yours;&lt;BR /&gt;
	input ddd mmddyy10. weather $20.;&lt;BR /&gt;
	datalines;&lt;BR /&gt;
06/02/2005 Tornado&lt;BR /&gt;
06/02/2005 Hail&lt;BR /&gt;
06/03/2005 Rain &lt;BR /&gt;
06/03/2005 Cloudy&lt;BR /&gt;
06/04/2005 Cloudy &lt;BR /&gt;
06/05/2005 Hail&lt;BR /&gt;
06/05/2005 Tornado &lt;BR /&gt;
06/05/2005 Rain&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=yours; by ddd; run;&lt;BR /&gt;
proc freq data=yours; table weather/out=out; run;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
	length weathers $100;&lt;BR /&gt;
	set out end=eof;&lt;BR /&gt;
	retain weathers ' ' cnt 0;&lt;BR /&gt;
	weathers = catx(' ', weathers, weather);&lt;BR /&gt;
	cnt + 1;&lt;BR /&gt;
	if eof then do;&lt;BR /&gt;
		call symputx('weathers', weathers);&lt;BR /&gt;
		call symputx('nWeather', cnt);&lt;BR /&gt;
	end;&lt;BR /&gt;
run;&lt;BR /&gt;
%put &amp;amp;weathers &amp;amp;nWeather; * check macro variables;&lt;BR /&gt;
&lt;BR /&gt;
data new;&lt;BR /&gt;
	set yours;&lt;BR /&gt;
	array vv[&amp;amp;nWeather] &amp;amp;weathers;&lt;BR /&gt;
	by ddd;&lt;BR /&gt;
	retain &amp;amp;weathers;&lt;BR /&gt;
	if first.ddd then do;&lt;BR /&gt;
		do i=1 to &amp;amp;nWeather;&lt;BR /&gt;
			vv&lt;I&gt; = 0;&lt;BR /&gt;
		end;&lt;BR /&gt;
	end;&lt;BR /&gt;
	do i=1 to &amp;amp;nWeather;&lt;BR /&gt;
		if weather = scan("&amp;amp;&amp;amp;weathers", i) then leave;&lt;BR /&gt;
	end;&lt;BR /&gt;
	if i &amp;lt;= &amp;amp;nWeather then vv&lt;I&gt; = 1;&lt;BR /&gt;
	if last.ddd then output;&lt;BR /&gt;
	drop i weather;&lt;BR /&gt;
	format ddd mmddyy10.;&lt;BR /&gt;
run;&lt;/I&gt;&lt;/I&gt;</description>
      <pubDate>Fri, 20 Jun 2008 19:17:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/HELP/m-p/13369#M1947</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-06-20T19:17:37Z</dc:date>
    </item>
  </channel>
</rss>

