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?
Example: This is how my dataset is at present.
I want my dataset to be changed in following way:
v1 v2 v3
6/2/2005 Tornado Hail
Above is the example of the dataset. The datset can contain same date with multiple storm conditions and not just two stotm conditions.
Can you please help me how to code this?
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.
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.
length weathers $100;
set out end=eof;
retain weathers ' ' cnt 0;
weathers = catx(' ', weathers, weather);
cnt + 1;
if eof then do;
call symputx('weathers', weathers);
call symputx('nWeather', cnt);
%put &weathers &nWeather; * check macro variables;
array vv[&nWeather] &weathers;
if first.ddd then do;
do i=1 to &nWeather;
vv = 0;
do i=1 to &nWeather;
if weather = scan("&&weathers", i) then leave;
if i <= &nWeather then vv = 1;
if last.ddd then output;
drop i weather;
format ddd mmddyy10.;