- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have this dataset
and I want this dataset with the var new
Thank you!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Edit : I did not pat attention to the row order => code modified a bit
Please provide data in the form of a datastep so we can test the solutions we propose before posting them.
Try this
data want;
set have;
array tt(*) tt75-tt80;
array a(6) _TEMPORARY_;
if anno<2018 then do;
a(2018-anno)=tt(anno-2011);
end;
else do;
new=a(anno-2016);
end;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Edit : I did not pat attention to the row order => code modified a bit
Please provide data in the form of a datastep so we can test the solutions we propose before posting them.
Try this
data want;
set have;
array tt(*) tt75-tt80;
array a(6) _TEMPORARY_;
if anno<2018 then do;
a(2018-anno)=tt(anno-2011);
end;
else do;
new=a(anno-2016);
end;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thats a bit of a mess of dataset. You can do it, but it would be hardcoded in a bit. E.g.
data want; set have; if anno=2018 then new=lag2(tt79); if anno=2019 then new=lag3(tt78); ... run;
I don't see a logical way of doing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Is there any particular reason why you chose the numbers you selected?
To create new variables, you must use one of the methods mentioned on this page: https://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000695113.htm
To help you out specifically in your case, I am going to need to know what the source of your data is (excel, datalines, sas dataset, .csv, etc.) to give you more information on how you can add the new variable and subset the observations.
You could use a when or an if statement to subset the variables to contain only those specific variables that only contain the observations you want. However, without knowing the reason why you want those specific numbers you chose, I am unable to help you out further.
Best Regards,
Daniel DuVal
SAS Technical Support
+1 (919) 531-2211
SAS ▪ SAS Campus Drive ▪ Cary, NC 27513
SAS® … THE POWER TO KNOW®
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The var new is a component of a formula to estimate the people over 80. I need, for every codice_comune, in anno 2018 the TT79 value-anno 2016, in anno 2019 the tt78 value-anno 2015, in anno 2020 the tt77 value-anno 2014, in anno 2021 the tt76 value-anno 2014 and in anno 2022 the tt75 value-anno 2013. This is my dataset
data have;
input codice_comune anno tt75 tt76 tt77 tt78 tt79 tt80 ;
datalines;
33001 2012 369 333 303 279 255 236
33001 2013 364 341 307 278 254 232
33001 2014 367 343 320 288 258 233
33001 2015 364 341 316 294 263 233
33001 2016 365 344 320 297 274 243
33001 2017 362 335 315 292 270 247
33001 2018 0 0 0 0 0 0
33001 2019 0 0 0 0 0 0
33001 2020 0 0 0 0 0 0
33001 2021 0 0 0 0 0 0
33001 2022 0 0 0 0 0 0
33002 2012 563 519 462 424 378 336
33002 2013 564 523 480 427 393 348
33002 2014 563 524 483 443 391 358
33002 2015 560 514 476 436 396 346
33002 2016 557 517 472 436 399 360
33002 2017 551 512 473 427 392 355
33002 2018 0 0 0 0 0 0
33002 2019 0 0 0 0 0 0
33002 2020 0 0 0 0 0 0
33002 2021 0 0 0 0 0 0
33002 2022 0 0 0 0 0 0
33003 2012 124 114 101 91 81 72
33003 2013 130 121 111 97 88 78
33003 2014 127 117 109 99 85 76
33003 2015 127 118 109 101 91 78
33003 2016 135 115 108 99 91 81
33003 2017 132 126 108 101 92 84
33003 2018 0 0 0 0 0 0
33003 2019 0 0 0 0 0 0
33003 2020 0 0 0 0 0 0
33003 2021 0 0 0 0 0 0
33003 2022 0 0 0 0 0 0
33004 2012 516 469 434 406 373 338
33004 2013 501 468 420 388 360 328
33004 2014 510 470 439 391 360 332
33004 2015 504 463 423 394 344 315
33004 2016 504 456 416 378 350 304
33004 2017 508 465 418 377 341 314
33004 2018 0 0 0 0 0 0
33004 2019 0 0 0 0 0 0
33004 2020 0 0 0 0 0 0
33004 2021 0 0 0 0 0 0
33004 2022 0 0 0 0 0 0
33005 2012 768 718 672 602 546 485
33005 2013 750 701 651 605 537 485
33005 2014 763 706 659 611 566 497
33005 2015 752 702 648 601 553 510
33005 2016 755 694 645 591 544 497
33005 2017 770 713 656 609 555 507
33005 2018 0 0 0 0 0 0
33005 2019 0 0 0 0 0 0
33005 2020 0 0 0 0 0 0
33005 2021 0 0 0 0 0 0
33005 2022 0 0 0 0 0 0
33006 2012 914 853 785 714 623 557
33006 2013 933 853 795 732 665 579
33006 2014 976 888 808 748 687 622
33006 2015 997 922 835 756 696 636
33006 2016 991 919 847 762 687 632
33006 2017 991 916 844 773 692 621
33006 2018 0 0 0 0 0 0
33006 2019 0 0 0 0 0 0
33006 2020 0 0 0 0 0 0
33006 2021 0 0 0 0 0 0
33006 2022 0 0 0 0 0 0
33007 2012 602 549 510 469 426 376
33007 2013 610 559 507 469 431 390
33007 2014 613 558 507 459 422 386
33007 2015 629 571 517 470 421 384
33007 2016 643 577 522 473 428 381
33007 2017 663 599 533 480 432 386
33007 2018 0 0 0 0 0 0
33007 2019 0 0 0 0 0 0
33007 2020 0 0 0 0 0 0
33007 2021 0 0 0 0 0 0
33007 2022 0 0 0 0 0 0
33008 2012 261 235 208 185 160 141
33008 2013 264 235 212 186 163 138
33008 2014 270 243 214 192 169 148
33008 2015 283 256 229 203 182 160
33008 2016 290 265 240 214 189 169
33008 2017 284 266 240 215 190 167
33008 2018 0 0 0 0 0 0
33008 2019 0 0 0 0 0 0
33008 2020 0 0 0 0 0 0
33008 2021 0 0 0 0 0 0
33008 2022 0 0 0 0 0 0
;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes, it's perfect! Thank you!