BookmarkSubscribeRSS Feed
priyankkhare88
Calcite | Level 5

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.

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

priyankkhare88
Calcite | Level 5
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.
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.    

priyankkhare88
Calcite | Level 5

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
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

ballardw
Super User

@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?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 16692 views
  • 0 likes
  • 3 in conversation