Desktop productivity for business analysts and programmers

Create a blank dataset

Reply
New Contributor
Posts: 4

Create a blank dataset

[ Edited ]

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.

Esteemed Advisor
Esteemed Advisor
Posts: 7,253

Re: Create a blank dataset

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.

New Contributor
Posts: 4

Re: Create a blank dataset

Thanks for your reply. But actually those questions were asked by someone to me. That is why i am asking over here. I have searched alot over internet, but could not get a proper solution.
Both are separate questions actually.
Esteemed Advisor
Esteemed Advisor
Posts: 7,253

Re: Create a blank dataset

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.    

New Contributor
Posts: 4

Re: Create a blank dataset

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.


Image1.png
Esteemed Advisor
Esteemed Advisor
Posts: 7,253

Re: Create a blank dataset

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.

Grand Advisor
Posts: 10,251

Re: Create a blank dataset


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?

Ask a Question
Discussion stats
  • 6 replies
  • 185 views
  • 0 likes
  • 3 in conversation