BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Gjax21
Calcite | Level 5

I am trying to create a new variable by dividing the values of single variable "SNinner_SNouter" where another variable has a values of '8' by that same variable "SNinner_SNouter" where that same other variable has a value of 19. 

 

I feel like i need some statement like    new var = "SNinner_SNouter" where value is 8    /    "SNinner_SNouter" where value is 19

 

 

I have attached the dataset. I appologise that my explanation is probably terrible. I'm not experienced at programming. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You can use the LAG function, or you can simply re-arrange the data as follows. Both assume the data is properly sorted.

 

data want;
    merge ratios(where=(global_timepoint=8) rename=(SNinner_SNouter=SN8))
        ratios(where=(global_timepoint=19) rename=(SNinner_SNouter=SN19));
    by date_of_experiment;
    ratio = SN19 / SN8;
run;

 

--
Paige Miller

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

@Gjax21 wrote:

I am trying to create a new variable by dividing the values of single variable "SNinner_SNouter" where another variable has a values of '8' by that same variable "SNinner_SNouter" where that same other variable has a value of 19. 

 

I feel like i need some statement like    new var = "SNinner_SNouter" where value is 8    /    "SNinner_SNouter" where value is 19

 

 

I have attached the dataset. I appologise that my explanation is probably terrible. I'm not experienced at programming.  

 


You need to explain more clearly what you want. 

Do the values you need to work with already appear on the same observation (or ROW if you are looking at your spreadsheet)?

If not how do you know which observations to combine so that the values ARE on the same observation?  Is there an id variable that would let you merge the observations together? 

 

Do you want to compare to the value on the previous observation?  Again what are the id variables and is the data already sorted?

 

Please post small sample data with minimal set of variables and observations to demonstrate the issue.  Please post in the form of a data step that can be used to create the dataset.  Not a copy of a spreadsheet.

Gjax21
Calcite | Level 5

 

data ratios;

input Date_of_Experiment$ Global_Timepoint    SNinner_SNouter ;     

cards;

2_15 8 0.99789
2_15 19 1.00253
2_18 8 1.07797
2_18 19 1.10799
2_20 8 0.9677
2_20 19 0.9748
2_27 8 1.08788
2_27 19 1.08133
;;;;;run;quit;

 

 

The experimental case is indicated by Date_of_Experiment. Global timepoint indicates a numerical designation of a point in time that corresponds to an experimental change. Within each experimental case indicated by "Date_of_Experiment" I want to divide the value of SNinner_SNouter  at timepoint 19 by the value at timepoint 8 and write the result as a new variable for each experimental case. As you can see the problem is that they are in different rows. 

PaigeMiller
Diamond | Level 26

You can use the LAG function, or you can simply re-arrange the data as follows. Both assume the data is properly sorted.

 

data want;
    merge ratios(where=(global_timepoint=8) rename=(SNinner_SNouter=SN8))
        ratios(where=(global_timepoint=19) rename=(SNinner_SNouter=SN19));
    by date_of_experiment;
    ratio = SN19 / SN8;
run;

 

--
Paige Miller
Gjax21
Calcite | Level 5

Thanks very much Paige! 

 

This worked very well once I sorted the data. I did not have much luck trying to figure out how to do it by googling. Quick and efficient. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 801 views
  • 0 likes
  • 3 in conversation