The primary ways to create looping in SAS are in DATA steps, and via macros. There is no looping in SQL unless you create a macro that works inside of SQL. You can also create indexes in PROC DATASETS, but again, there is no looping without macros that work inside of PROC DATASETS. So ... I think those are your choices.
The primary ways to create looping in SAS are in DATA steps, and via macros. There is no looping in SQL unless you create a macro that works inside of SQL. You can also create indexes in PROC DATASETS, but again, there is no looping without macros that work inside of PROC DATASETS. So ... I think those are your choices.
@PaigeMiller well, do you answer to the below question as well?
I'd like to know if we can create the index on a table (e.g., libname.test) and rename the table (e.g. libname.test_1). Does the index name get updated too?
Typically, my answer to a question that wants to know if something works or not:
Try it yourself and see.
I think that applies here as well.
I've tried the following program to create a index and I want to check whether index will be retained if we rename the dataset name which has index.
I observed that index is not being retained if we rename the dataset name. Is there a way to retain the index even if we rename the dataset name?
data cars; set sashelp.cars; run; proc contents data=cars noprint out=index_list(keep=libname memname name); run; filename code temp; data _null_; set index_list; by libname memname ; file code; if first.libname then put 'proc datasets nolist lib=' libname ';' ; if first.memname then put 'modify ' memname ';' / ' create index ' @; put name @; if last.memname then put ';' / 'run;' ; if last.libname then put 'quit;' ; run; %include code/ source2; data cars_new; set cars; run; proc contents data=cars_new; run; proc contents data=cars; run;
First you have to realize that
data cars_new; set cars; run;
Does not "copy" a data set. It builds a completely new data set setting all of its own properties including indexes (none). Second it has to process every single record.
If you want to copy to a Different library (COPY means keep the same name in this case so you can't have two sets with the same name in the same library). Or Proc Copy but again it goes to a new library.
libname Dest "<library location>"; Proc datasets library=work; copy out=dest; /*name of destination library*/ select cars; run; quit;
Or create the Cars_new and run the index afterwards.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.