BookmarkSubscribeRSS Feed
deleted_user
Not applicable
%macro TestGet(MACROV,Data=lib.test);
%local dsid;
%let dsid=%sysfunc(OPEN(&Data(where=(NAME="&NAME"))));
%let dsid=%sysfunc(CLOSE(&dsid));
%mend TestGet;
________________________________________________

%macro hey;
%let service=%TestGet(can,data=lib.test);
%put &service;
%mend;

________________________________________________

My Dataset is:

id name
1 ali
2 veli
3 can
4 cin

I've written two pieces of macro procedures. First macro is to generalize of retrieving a data from a dataset. First parameter is the data to be looked up in the dataset,and the second is the dataset name. I've created a local macro variable to initialize the look-up data to that variable.
So in the second procedure, i am trying to get the look-up data in the dataset and try tp print it to the log.

But i am proably doing something wrong. Could you please help me.

Best Regards,
Can Akcan
6 REPLIES 6
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Cakcan,

I am not sure what you are going to acheve. If you would like to test a succes of opening and closing a dataset then the following change to your code could help:

data a;
input id name $;
datalines;
1 ali
2 veli
3 can
4 cin
run;

options symbolgen mprint;

%macro TestGet(name,Data=lib.test);
%global dsid dsid1;
%let dsid=%sysfunc(OPEN(&Data(where=(NAME="&NAME"))));
%let dsid1=%sysfunc(CLOSE(&dsid));
%mend TestGet;

%macro hey;
%TestGet(name,data=work.a);
%put dsid=&dsid dsid1=&dsid1;
%mend;

%hey

Sincerely,
SPR
deleted_user
Not applicable
my aim is to open a dataset, assign variable to a macro variable in the dataset and close it and then finally i have a generalized function which i write the name of the dataset and the column name and retieve the data from the that dataset. thats it. I hope it is clear.
SPR
Quartz | Level 8 SPR
Quartz | Level 8
This my second attempt to understand what you need. The code below creates a dataset _a that contains the observation from input dataset for name="can". Is this what you need? or you need only ID for "can"?

%macro TestGet(name,Data=lib.test);
%local dsid;
%let dsid=%sysfunc(OPEN(&Data(where=(NAME="&NAME"))));
%if &dsid NE 0 %then %do;
data _a;
set &Data(where=(NAME="&NAME"));
run;
%end;
%else %put Error in &data;
%let dsid=%sysfunc(CLOSE(&dsid));
%mend TestGet;

%macro hey;
%TestGet(can,data=work.a);
proc print data=_a;
run;
%mend;

%hey
ArtC
Rhodochrosite | Level 12
Cakcan,
Notice then name change of the positional parameter in SPR's code. But I am worried about your statement of the problem. We are a bit confused because macro variables are not, in any way, assigned to data sets. You do not need to open a data set to create a macro variable. Macro variables are held in memory for the duration of the SAS job or session. The values of macro variables can be used in the process of data set variable creation and assignment, but that is a very different process than the one you have started here.
Art
deleted_user
Not applicable
Thank you for your comments. I've got to the point where i want to achieve.
Thanx a lot.

Best Regards,
Cakcan

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 786 views
  • 0 likes
  • 4 in conversation