Hi,
I have a simple do-loop:
data nobs;
do i=i to 2;
data nobs_i;
set nobs_i;
keep Nobsused;
end;
run;
It is giving me the following error msg: No Matching DO/SELECT statement. Why?
The second data statement begins a new data step, so the do in the old one has no matching end. What are you trying to do?
The basic step would be
data nobs;
set
nobs_1
nobs_2
;
keep Nobsused;
run;
If you have an arbitrary number of datasets, use
set
nobs_1-nobs_&n.
;
if your number of datasets is stored in macro variable n.
Back to the original question then, what are you trying to accomplish here?
@GKati wrote:
Ok, this is helpful. But what if I wanted to keep the two datasets separete?
What is NObsUsed?
@GKati wrote:
I'm trying to figure out do-loops with a simple example. I have two datasets: nobs_1 and nobs_2. I would like to keep Nobsused in both datasets without merging the two datasets.
I am going to have about 16 different datasets that I need to modify. I need to keep them separately and run a code through them one-by-one.
Thanks
I'm not a fan of twenty questions. Please explain your process in detail.
The approach you're currently trying doesn't make sense for any process.
@GKati wrote:
It's variable.
If you state what you're trying to achieve we can recommend the best method.
For example, PROC DATASETS is more efficient to modify data sets to drop/keep variables that multiple data steps. If you take the approach used in other programming languages and try and apply them to another language, you miss learning how to efficiently use the new language.
Or that you can easily create a view with just the one variable that only gets created when called.
@GKati wrote:
gamotte, Reeza
Thanks for your help. My intention was not to waste your time. I have been looking at do-loop examples and that is how I came up with the code above. My intuition comes from STATA, where it is possible to loop over different datasets and modify them without merging them. I now understand that that is not possible in SAS and that I need to write a macro to do that. I will try that and see how I do.
Thanks for your time.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.