BookmarkSubscribeRSS Feed
Obsidian | Level 7

Hi All,


I have longitudnal data and grp variable and fl variable, values of grp as 1 2 3 4 5 6... and values for fl as 1 2 3... need to create variable net.

Is there any dynamic way to get the grp and fl values


if grp=1 then do; if fl=1 then net=1; if fl=2 then net=2;end;
if grp=2 then do; if fl=1 then net=3; if fl=2 then net=4;end;
if grp=3 then do; if fl=1 then net=5; if fl=2 then net=6;end;
if grp=4 then do; if fl=1 then net=7; if fl=2 then net=8;end;



my try :

%let maxgrp=4;%let fl=2;

proc sql;

 select *,

%do i=1 %to &maxgrp;  j=1 %to &fl;

     case when grp=&i and fl eq &j then &i*&j;

    end as trt

from ids;






Super User
You can simplify it to a formula:

Obsidian | Level 7

Thank you Reeza!!!

can we adopt this formula under the sql? if i used in data step i got the output , but if i want to adopt for sql, getting warning on log,

"net variable already exit in XXXX dataset"






Super User
In SQL it would work as well but it would be
(2*(grp-1))+fl as net

If the NET variable already exists in the dataset, as your warning indicates that something to be cautious of, do you really want to overwrite the other variable called net. In a data step it would overwrite it without any warning.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 2 in conversation