BookmarkSubscribeRSS Feed
shanky_44
Obsidian | Level 7

Hello everyone, 

 

I am new to SAS and trying to learn as much  as possible. While practicing, I came across a data set in which I need to create a variable with particular observations. I think this problem can be solved from first. and last. observation. However, expecting experts feedback and please provide alternate solutions as well as, if possible. Thanks !

 

Problem ; 

data is similar to this scenario: new var is a character variable 

 

name  country  gender  New_var 

x          Y           M              D1

x1         Y1        F               D2 

X2         Y2       M              D1

X3         Y3       M              D2

 

Here I have created new_var and I have D1 and D2 values but I need to have D1 +D2 observation is same variable along existing observation.        

9 REPLIES 9
PGStats
Opal | Level 21

I suggest you start by reviewing the definitions of Observation and Variable in SAS. Then you might want to reword your question.

PG
shanky_44
Obsidian | Level 7

shell.PNG

this is the shell. ROI variable is not in our data,  I have created ROI varibale with ROI 1 and ROI 2 observation in data set with the help of one variable. Now I want ROI 1 + ROI 2 in same variable with  other observation.  I know it is not explained well but in this platform and the technicality of work, I am not able to explain everything. I apologize  and thanks for everyone for trying to help me out. 

Reeza
Super User
This may be easier if you show what you have as a starter and what you want as the final output. I *think* you're starting with name, country, and gender, and you're trying to calculate New_var?
shanky_44
Obsidian | Level 7

Hi Reeza, 

 

Actually, it is a lengthy work I can share everything here. I have posted a shell above and I have to create listing for that. The issue was variable ROI is not in our data so i have created a variable in data set and populated the value on the basis of other variable. But I need one more observation which should be ROI 1 + ROI 2 . I was not clear how to get that. I am really sorry it is still messed up. I am not able to explain clearly, but thanks for the help. while posting this, I think I got the answer. Thanks.

Reeza
Super User

Look up multilabel formats, with PROC MEANS or TABULATE is likely what you need.

 

Or PROC TABULATE can do it all at once. 

 

proc tabulate data=sashelp.class;
class sex age;
var height;

table (sex all = 'M + F')* age , height*(mean median min max);
run;

 

 

shanky_44
Obsidian | Level 7

Hi Reeza, 

 

This problem is more about creating dummy variables and then transpose them on some parameters. By the shell it looks like it is calculation scenario but it is not. Even I have not clarified the things properly here because it is a lengthy process and I am just asking  in mid where ever I get struck. Thanks for the help!

Reeza
Super User

I think you need to go back and answer this question then, I'm clearly not the only confused by your question. 

 

This may be easier if you show what you have as a starter and what you want as the final output

 

Also, dummy variables aren't needed for most procedures, SAS will create them automatically. If you need to create dummy variables, there are several easy ways to do so and then you can test the various hypothesis using contrast statements.

 


@shanky_44 wrote:

Hi Reeza, 

 

This problem is more about creating dummy variables and then transpose them on some parameters. By the shell it looks like it is calculation scenario but it is not. Even I have not clarified the things properly here because it is a lengthy process and I am just asking  in mid where ever I get struck. Thanks for the help!


 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

Wow that is almost confusing.

 

Please post a sample dataset of what you want and the SAS code you have tried.  Your sample code might assist the community with understanding your request.

 

shanky_44
Obsidian | Level 7

Hi Reeza,

 

Yeah, I know and I apologize for that. This is a listing format and a long process. I am just asking where i am confused with either data orientation (transpose rule) or new dummy data creation. I would not be able to share data here. However, I am really thankful for your efforts. At least I have learned one new thing which you mentioned in Proc tabulate. 

I hope you will understand. and I will try to explain better next time for further queries. 

 

Thanks Everyone!

Shanky

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 9 replies
  • 1363 views
  • 1 like
  • 4 in conversation