Hello Friends,
I have 2 queries-
1. I want to create a blank dataset with 5 variables and 10 observations.
2. I want to drop all blank datasets in a library.
Please tell me the simplest way to create these 2 programs. Please provide code if possible.
Thanks in advance.
Hi,
Well, in response:
1) Why would you want to create empty datasets
2) Why do you have empty datasets
Its a bit like saying, I levelled off the land to put a shed on, now I want to get rid of that land. Why both doing the task in the first place?
If you really must create empty datasets, and I would advise against it:
data want; length var1--var2 $100; do i=1 to 5; output; end; run;
But that is just wasting disk space. You could create a template dataset by:
proc sql; create table WANT (var1 char(100),..var5 char(100)); quit;
And then add data in, that can sometimes be useful.
Now your second question is actually quite complicated, and unless you really have a good reason, I would avoid doing it. You would have to scan through each dataset/column, establish if each is empty, then in total for each dataset, then drop those. Really complicted and really adds no value to anything, just don't create empty datasets in the first place.
Then respond back to the person asking you this question to provide a good reason to do such a thing. Would not the reason for not finding an answer easily be that nobody does this? As mentioned I can understand if you want a template dataset with no data, that you then append to, and that is shown in my example. I can't think of any reason you would want to create empty datasets, or if you really did create, them why you would not know or have some naming convetion to isolate these.
OK.
Now, i have another question related to macros.
Question- I need to write a macro program to create the dataset as shown in attached examples. It should be dynamic and the output should change based on text and numbers
* The number should always be an odd number
Thanks in advance.
Are these college questions? There is no business scenario where this would occur. Datasets are oblongs of data. You can create structure simply:
data _null_; do i=1,3,5,7; call execute(cats('data out',put(i,best.),'; array var{',put(i,best.),'} $1; run;')); end; run;
As for creating patterns in those dataset, I am afraid I don't have time for that.
@priyankkhare88 wrote:
OK.
Now, i have another question related to macros.
Question- I need to write a macro program to create the dataset as shown in attached examples. It should be dynamic and the output should change based on text and numbers
* The number should always be an odd number
Thanks in advance.
Do the values ever contain more than one character? Does this "program" have to decide if the variables are numeric or character or just display a repeated value?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.