Hello, I am trying to subset variables from the below dataset. I know I can use the colon as suffix wildcard such as if I want all 'phys_chiro' variables. Is there a wildcard that I can use in the middle of the variable? Such as if I want all phys variables from 02 and 04 ('phys_#_02' and 'phys_#_04').
data dataset;
input phys_chiro_01 phys_chiro_02 phys_chiro_03 phys_ped_01 phys_ped_02 phys_ped_03 phys_derm_01 phys_derm_02 phys_derm_03 phys_general_01 phys_general_02 phys_general_03 phys_neuro_01 phys_neuro_02 phys_neuro_03;
datalines;
982 256 232 47 497 751 38 238 305 741 957 568 361 401 473
965 828 865 10 98 668 154 314 38 98 637 673 328 267 291
994 280 396 789 852 774 778 539 47 789 817 168 72 110 177
498 168 462 826 170 632 750 507 893 865 997 161 191 252 244
179 675 826 204 99 618 190 930 627 892 230 517 94 54 482
427 7 712 362 538 439 790 650 303 555 943 170 238 743 799
279 947 485 448 204 56 567 132 20 291 83 355 404 406 271
84 251 280 784 167 411 974 876 640 972 780 818 761 754 168
983 510 109 904 556 439 816 185 48 989 833 451 496 33 265
414 279 778 244 201 123 638 147 246 881 441 541 727 733 263
358 350 977 118 319 904 430 541 223 411 502 290 103 750 735
467 773 822 380 77 979 320 840 323 253 889 278 662 369 8
816 840 552 124 34 869 819 796 178 667 884 794 314 107 513
299 391 556 545 187 507 232 90 226 378 222 827 502 283 233
671 719 601 762 310 353 33 465 104 521 159 427 623 158 138
39 954 609 408 64 857 966 882 270 632 622 980 549 230 264
458 812 594 253 207 5 694 667 738 321 738 572 163 240 376
348 291 655 758 785 335 697 456 108 187 514 428 730 185 633
516 663 365 542 623 343 244 986 251 289 568 389 329 967 369
142 182 307 419 499 101 460 370 373 500 619 54 163 724 272
;
proc print;
run;
There are no mechanisms to filter using something similar to the colon.
You can build yourself a custom list by querying sashelp.vcolumn though.
proc sql noprint;
select name into :var_list separated by " "
from sashelp.vcolumn
where upcase(memname) = 'DATASET'
and libname = 'WORK'
and (upcase(name) like 'PHYS_%_02'
or upcase(name) like 'PHYS_%_03'
or upcase(name) like 'PHYS_%_04');
quit;
%put &var_list;
The WHERE clause can be customized as necessary to extract the required information.
@axescot78 wrote:
Hello, I am trying to subset variables from the below dataset. I know I can use the colon as suffix wildcard such as if I want all 'phys_chiro' variables. Is there a wildcard that I can use in the middle of the variable? Such as if I want all phys variables from 02 and 04 ('phys_#_02' and 'phys_#_04').
data dataset; input phys_chiro_01 phys_chiro_02 phys_chiro_03 phys_ped_01 phys_ped_02 phys_ped_03 phys_derm_01 phys_derm_02 phys_derm_03 phys_general_01 phys_general_02 phys_general_03 phys_neuro_01 phys_neuro_02 phys_neuro_03; datalines; 982 256 232 47 497 751 38 238 305 741 957 568 361 401 473 965 828 865 10 98 668 154 314 38 98 637 673 328 267 291 994 280 396 789 852 774 778 539 47 789 817 168 72 110 177 498 168 462 826 170 632 750 507 893 865 997 161 191 252 244 179 675 826 204 99 618 190 930 627 892 230 517 94 54 482 427 7 712 362 538 439 790 650 303 555 943 170 238 743 799 279 947 485 448 204 56 567 132 20 291 83 355 404 406 271 84 251 280 784 167 411 974 876 640 972 780 818 761 754 168 983 510 109 904 556 439 816 185 48 989 833 451 496 33 265 414 279 778 244 201 123 638 147 246 881 441 541 727 733 263 358 350 977 118 319 904 430 541 223 411 502 290 103 750 735 467 773 822 380 77 979 320 840 323 253 889 278 662 369 8 816 840 552 124 34 869 819 796 178 667 884 794 314 107 513 299 391 556 545 187 507 232 90 226 378 222 827 502 283 233 671 719 601 762 310 353 33 465 104 521 159 427 623 158 138 39 954 609 408 64 857 966 882 270 632 622 980 549 230 264 458 812 594 253 207 5 694 667 738 321 738 572 163 240 376 348 291 655 758 785 335 697 456 108 187 514 428 730 185 633 516 663 365 542 623 343 244 986 251 289 568 389 329 967 369 142 182 307 419 499 101 460 370 373 500 619 54 163 724 272 ; proc print; run;
Transpose such a dataset and extract types and sequence from _NAME_. As soon as you have such data as data, you can use tools like LIKE in SQL
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.