BookmarkSubscribeRSS Feed
ahmedkhan
Calcite | Level 5

Hi, I am new to SAS. Have searched a lot but I am unable to find the solution. My problem is that I want to generate a new variable based on the values of two other variables. An example is given below. 

what I Have is

Company id            Quarter   Start   End

1                             1             130      133

1                             2              190     194

1                             3             230      231

 

what I want is

Company id             Quarter   Start   End    Days

1                               1              130    133       130

1                               1                                     131

1                               1                                     132

1                               1                                     133

1                                2             190     194      190

1                                2                                    191

1                                2                                    192

1                                2                                    193

1                                2                                    194

1                                3                  230   231    230

1                                3                                     231

 

 

Only Quarters, Days & company id is required/important. I have around 30,000+ quarters, with each quarter having a different start and end. Any simple way to do it? for every company, there are 81 quarters and there are 500 companies which all have a unique id. 

 

Thanks a lot. 

 

1 REPLY 1
ChrisNZ
Tourmaline | Level 20

Like this?


data WANT;
  set HAVE;
  _LAST=END;
  do DAYS=START to _LAST;
    if DAYS ne START then call missing(START, END);
    output;
  end;
  drop _:;
run;
    
COMPANY_ID QUARTER START END DAYS
1 1 130 133 130
1 1 . . 131
1 1 . . 132
1 1 . . 133
1 2 190 194 190
1 2 . . 191
1 2 . . 192
1 2 . . 193
1 2 . . 194
1 3 230 231 230
1 3 . . 231

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 161 views
  • 0 likes
  • 2 in conversation