BookmarkSubscribeRSS Feed
JUMMY
Obsidian | Level 7

So I have this data that contains so many numerical variables. I want to create a new variable from two of the variables such that 1="any fracture" and 2="non fracture" but the new variable should be numerical. How do I do this?

 

Obs studyid sdem idem female age sanyapcnsrx santipsychrx scnsrx sconven satypical sbenzo

1 M0001 1 yes yes 85.6016 33 15 33 0 15 3
2 M0002 6 yes no 93.3580 1 0 1 0 0 1
3 M0003 1 yes yes 86.6146 45 0 45 0 0 9
4 M0007 5 yes yes 74.8720 8 2 8 0 2 0
5 M0008 1 yes no 83.5975 5 0 5 0 0 2
6 M0010 34 yes yes 77.2402 8 2 8 0 2 1
7 M0011 1 yes yes 79.5400 0 0 0 0 0 0
8 M0014 1 yes yes 78.7543 4 0 4 0 0 0
9 M0016 3 yes no 62.7105 58 0 58 0 0 0
10 M0018 8 yes no 70.3792 8 3 8 0 3 0
11 M0020 1 yes yes 49.3908 1 0 1 0 0 0
12 M0022 4 yes no 85.2923 76 2 76 0 2 1
13 M0025 1 yes no 78.8611 10 0 10 0 0 2
14 M0028 8 yes yes 74.3053 13 0 13 0 0 0
15 M0035 2 yes yes 74.6831 33 0 33 0 0 1
16 M0036 1 yes yes 54.5243 72 12 72 1 11 6
17 M0041 1 yes yes 87.5044 3 0 3 0 0 0
18 M0044 6 yes yes 71.0609 18 0 18 0 0 1
19 M0047 14 yes yes 81.0924 49 20 49 0 20 1
20 M0056 5 yes yes 80.7064 61 0 61 0 0 40
21 M0058 1 yes yes 47.4470 29 0 29 0 0 0
22 M0060 1 yes no 84.7474 101 0 101 0 0 0
23 M0062 1 yes no 51.1239 29 0 29 0 0 0
24 M0065 8 yes yes 76.4873 1 0 1 0 0 0
25 M0070 3 yes yes 60.9035 62 0 62 0 0 1
26 M0074 10 yes no 59.3018 61 8 61 0 8 26
27 M0079 1 yes no 78.0616 17 0 17 0 0 0
28 M0080 1 yes yes 80.8816 2 0 2 0 0 0

 

So say I want to create a new variable from "sanyapcnsrx" and "santipsychrx" using 1='any fracture' and 0='non fracture' such that I can run proc means. What do I do?

7 REPLIES 7
novinosrin
Tourmaline | Level 20

why not just format is using proc format without having to create a new variable?

JUMMY
Obsidian | Level 7
the problem is that I want to find proc means. How do i do that with character variables if i decide to use proc format?
novinosrin
Tourmaline | Level 20

Can you post a sample of what you have and what you want explaining the current data type of the vars

PaigeMiller
Diamond | Level 26

PROC FORMAT leaves the variables as numeric, if they were numeric to begin with, so you can do math on them.

 

But, please, show us a portion of your data.

--
Paige Miller
JUMMY
Obsidian | Level 7
@PaigeMiller, I just posted some data above. So say I want to create a new variable from "sanyapcnsrx" and "santipsychrx" using 1='any fracture' and 0='non fracture' such that I can run proc means. What do I do?
PaigeMiller
Diamond | Level 26

@JUMMY wrote:

So I have this data that contains so many numerical variables. I want to create a new variable from two of the variables such that 1="any fracture" and 2="non fracture" but the new variable should be numerical. How do I do this?

 

Obs studyid sdem idem female age sanyapcnsrx santipsychrx scnsrx sconven satypical sbenzo

1 M0001 1 yes yes 85.6016 33 15 33 0 15 3
2 M0002 6 yes no 93.3580 1 0 1 0 0 1
3 M0003 1 yes yes 86.6146 45 0 45 0 0 9
4 M0007 5 yes yes 74.8720 8 2 8 0 2 0
5 M0008 1 yes no 83.5975 5 0 5 0 0 2
6 M0010 34 yes yes 77.2402 8 2 8 0 2 1
7 M0011 1 yes yes 79.5400 0 0 0 0 0 0
8 M0014 1 yes yes 78.7543 4 0 4 0 0 0
9 M0016 3 yes no 62.7105 58 0 58 0 0 0
10 M0018 8 yes no 70.3792 8 3 8 0 3 0
11 M0020 1 yes yes 49.3908 1 0 1 0 0 0
12 M0022 4 yes no 85.2923 76 2 76 0 2 1
13 M0025 1 yes no 78.8611 10 0 10 0 0 2
14 M0028 8 yes yes 74.3053 13 0 13 0 0 0
15 M0035 2 yes yes 74.6831 33 0 33 0 0 1
16 M0036 1 yes yes 54.5243 72 12 72 1 11 6
17 M0041 1 yes yes 87.5044 3 0 3 0 0 0
18 M0044 6 yes yes 71.0609 18 0 18 0 0 1
19 M0047 14 yes yes 81.0924 49 20 49 0 20 1
20 M0056 5 yes yes 80.7064 61 0 61 0 0 40
21 M0058 1 yes yes 47.4470 29 0 29 0 0 0
22 M0060 1 yes no 84.7474 101 0 101 0 0 0
23 M0062 1 yes no 51.1239 29 0 29 0 0 0
24 M0065 8 yes yes 76.4873 1 0 1 0 0 0
25 M0070 3 yes yes 60.9035 62 0 62 0 0 1
26 M0074 10 yes no 59.3018 61 8 61 0 8 26
27 M0079 1 yes no 78.0616 17 0 17 0 0 0
28 M0080 1 yes yes 80.8816 2 0 2 0 0 0

 

So say I want to create a new variable from "sanyapcnsrx" and "santipsychrx" using 1='any fracture' and 0='non fracture' such that I can run proc means. What do I do?


I'm afraid this doesn't tell us anything. You want to "create a new variable"? How? What do you want to do to create this new variable? Add them together? Divide them? Add the arccosines squared? Explain.

 

Also, @JUMMY, from now on, we expect you to post sample data every single post you make, using this method: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... because the data you did post is unbelievably difficult for humans to read.

--
Paige Miller
ballardw
Super User

@JUMMY wrote:

So I have this data that contains so many numerical variables. I want to create a new variable from two of the variables such that 1="any fracture" and 2="non fracture" but the new variable should be numerical. How do I do this?

 

Obs studyid sdem idem female age sanyapcnsrx santipsychrx scnsrx sconven satypical sbenzo

1 M0001 1 yes yes 85.6016 33 15 33 0 15 3
2 M0002 6 yes no 93.3580 1 0 1 0 0 1
3 M0003 1 yes yes 86.6146 45 0 45 0 0 9
4 M0007 5 yes yes 74.8720 8 2 8 0 2 0
5 M0008 1 yes no 83.5975 5 0 5 0 0 2
6 M0010 34 yes yes 77.2402 8 2 8 0 2 1
7 M0011 1 yes yes 79.5400 0 0 0 0 0 0
8 M0014 1 yes yes 78.7543 4 0 4 0 0 0
9 M0016 3 yes no 62.7105 58 0 58 0 0 0
10 M0018 8 yes no 70.3792 8 3 8 0 3 0
11 M0020 1 yes yes 49.3908 1 0 1 0 0 0
12 M0022 4 yes no 85.2923 76 2 76 0 2 1
13 M0025 1 yes no 78.8611 10 0 10 0 0 2
14 M0028 8 yes yes 74.3053 13 0 13 0 0 0
15 M0035 2 yes yes 74.6831 33 0 33 0 0 1
16 M0036 1 yes yes 54.5243 72 12 72 1 11 6
17 M0041 1 yes yes 87.5044 3 0 3 0 0 0
18 M0044 6 yes yes 71.0609 18 0 18 0 0 1
19 M0047 14 yes yes 81.0924 49 20 49 0 20 1
20 M0056 5 yes yes 80.7064 61 0 61 0 0 40
21 M0058 1 yes yes 47.4470 29 0 29 0 0 0
22 M0060 1 yes no 84.7474 101 0 101 0 0 0
23 M0062 1 yes no 51.1239 29 0 29 0 0 0
24 M0065 8 yes yes 76.4873 1 0 1 0 0 0
25 M0070 3 yes yes 60.9035 62 0 62 0 0 1
26 M0074 10 yes no 59.3018 61 8 61 0 8 26
27 M0079 1 yes no 78.0616 17 0 17 0 0 0
28 M0080 1 yes yes 80.8816 2 0 2 0 0 0

 

So say I want to create a new variable from "sanyapcnsrx" and "santipsychrx" using 1='any fracture' and 0='non fracture' such that I can run proc means. What do I do?


For obs=1 your sanyapcnsrx variable is 33 and santipsychrx is 15. HOW do we know from the values of the two variables whether this is a "any fracture" or "non fracture"? We need to know the rules for identifying the condition our are requesting/

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 2214 views
  • 0 likes
  • 4 in conversation