Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SAS data set from scratch

Status
Not open for further replies.

sas2010

Programmer
Apr 14, 2008
3
Hi all,
is it possible to create a SAS data set without importing data from any file. I want to build from scratch a data set that will contain the days of the month of February 2008. No infile, no cards, no datalines.
Just some simple logic I could use for generating anytime my 28, 29, 30 or 31 days for any month.
Again, I need a data set with one variable, and as many observations as days in a month, the observations will be formated as date9.

Thanks,
kowalsky
 
I am not sure why you need this as there are so many formats and functions that can be used to figure out the numbe rof days in the month, but here is some code.

Code:
data test;
 month = 2; *** NUMBER OF THE MONTH IN THE CALENDAR 1=JAN, 2=FEB...***;
 year  = 2008; *** ENTER THE YEAR ***;
 mdate = mdy(month,1,year);
 do i=1 to 31;
  if month(mdate) = month then
    output;
  mdate+1;
 end;
 keep mdate;
 
 format mdate date9.;
 
run;

Hope this helps you.
Klaz
 
That's exactly what I needed - it's really simple if you know the basics - somehow I believe that the documentation available even though massive it's not what I expected. It most probably is my biased perception, but I find it extremely difficult to find examples on a topic - I definitely don't know where to look for them; can you recommend something?

thanks a lot,
kowalsky
 
The "My Little SAS Book" is widely touted as a really good reference for newcomers to SAS. Once you know a reasonable amount of SAS and how it works, the doco becomes alot easier to understand (ie you know the construction of Do loops etc, so you know where to look when you want to do something like that). It's a common problem with learning a new language I think. If you don't know it, you don't know where to look in the doco.

I'd suggest, that now you've got your answer on this topic you'd do well to go look it up in the doco to learn about the other ways it can be used (ie the differences between "DO Until" and "Do While" and the "Iterative Do" {which is what Klaz used above}). You'll learn more about SAS and also get more comfortable with the doco.
The online doco is a great source of info.
Also the support.sas.com website has a bunch of articles and examples which can also be useful.


Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
thak you all for the tips,
i'll probably bother you more,
thanks again,
kowalsky
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top