BookmarkSubscribeRSS Feed
viollete
Calcite | Level 5

I have SAS dataset with 2 variables and n observations, from this dataset how can i create a new SAS dataset  with n variables and n observations, and every cell represent the ratio of these variables?

2 REPLIES 2
art297
Opal | Level 21

Can you provide an example and the maximum value that n might have?

PGStats
Opal | Level 21

Is this what you want?

data have;
input v1 v2;
datalines;
1 2
3 4
2 3
5 6
4 2
;

data h;
set have;
i = _n_;
run;

proc sql;
/* i and j are added in case there are duplicate consecutive v1 or v2 values */
create table ratios as
select a.v1, a.i as i, b.v2, b.i as j, a.v1/b.v2 as ratio
from h as a cross join h as b;
quit;

proc transpose data=ratios
out=want(drop=_name_) delimiter=_;
by v1 i notsorted;
id j v2;
var ratio;
run;

PG

PG

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
  • 2 replies
  • 367 views
  • 3 likes
  • 3 in conversation