BookmarkSubscribeRSS Feed
Ravikumarpa4
Obsidian | Level 7
Hi how to write a macro to extract first obs from library which is shorted by crdate if first obs is blank then its need to extract second obs so on... Kindly help me
15 REPLIES 15
Reeza
Super User

When you need to write a macro you first need working code and then you convert it. 

Do you have working code that needs to be turned into a macro? And since this is a trivial task why do you need a macro? Which parts are dynamic in nature. Please be more explicit in your questions. 

Ravikumarpa4
Obsidian | Level 7
Hi

Yes I've working code, whenever I run the working code it'll generate new
dataset here I need only that dataset some times if data is not available
old dataset will be there. So I need write a macro so that it can extractt
first obs dataset.

Thanks and Regards
Ravikumar

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Ravikumarpa4
Obsidian | Level 7
Hi
Code which I wrote is
Proc sql;
Create table abc as
Select * from
Dictionary.tables
Where libname= 'common'
Order by crdate desc;
Quit;

When I'm running above code its shows all the datasets in that library but
I want only one data set which is created most recently by writing macro.
Thanks

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Ravikumarpa4
Obsidian | Level 7
Hi

Now coding is working fine but I need assign macro how to do that,?

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Ravikumarpa4
Obsidian | Level 7
Hi

crdate part

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Ravikumarpa4
Obsidian | Level 7
Hi
variable will be same but value will change

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Reeza
Super User

But the max crdate is always used. If the variable name doesn't change that doesn't need to be parametrized. 

 

Post a few different versions of what the code would be for us to understand what you need a macro for. 

Ravikumarpa4
Obsidian | Level 7
Hi

Now I need to assign macro to 'memname' variable then how can I do.

Thanks

##- Please type your reply above this line. Simple formatting, no
attachments. -##
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post code, and examples to clarify the question.  As for your problem, why do you need a macro?

/* Test data */
proc sql; create table a (a char(2)); quit; data b; b=1; run; /* This is the code */ proc sort data=sashelp.vtable out=inter; by memname; where libname="WORK" and nobs > 0; run; data _null_; set inter (obs=1); call execute(cats('data want; set work.',memname,' (obs=1); run;')); run;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 15 replies
  • 1483 views
  • 2 likes
  • 4 in conversation