Solved

SAS Data Sets Manipulations

Posted on 2010-08-18
8
1,089 Views
Last Modified: 2013-11-16
I am trying to use external MACRO throughout my program to get a number value from "var1" to inside of one of my file names "file_&var1.DAT":

Note:
1.  "var1" is not in the dataset "data1"
2.  "var1" may be a number from 01 to 99

%let var1=%SYSGET (var5);
%MACRO START;

data _null_;
file 'dirname:file_&var1.DAT';
 set lib.data1
  put @1 var2 $char2.
        @3 var3 $char2.
        @5 var4 $char3.
        @8 var5 $char2.
        @10 var6 $char1.;
run;
     
%MEND START;
%START;

Please let me know what am I doing wrong here?
I am getting the following WARNING: The argument to macro function %SYSGET is not defined as a system variable.
0
Comment
Question by:labradorchik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 9

Accepted Solution

by:
bradanelson earned 250 total points
ID: 33469814
Where is var5 coming from in the following statement?
%let var1=%SYSGET (var5);


Once you have the GLOBAL VARIABLE var1 set, here is how to use it in the filename.  Notice the double quotes and the extra period I placed after the GLOBAL VARIABLE name.

%MACRO START;

data _null_;
file "dirname:file_&var1..DAT";
 set lib.data1
  put @1 var2 $char2.
        @3 var3 $char2.
        @5 var4 $char3.
        @8 var5 $char2.
        @10 var6 $char1.;
run;
     
%MEND START;
%START;
0
 

Author Comment

by:labradorchik
ID: 33469946
"var5" number value should come from the "var5" from the data1 data set. Am I doing something wrong here?
0
 
LVL 7

Expert Comment

by:d507201
ID: 33470042
%sysget is used to access environment variables like sasroot.  I don't think you want to have it here unless you're using the -sysparms statement when SAS session initializes.  

You're not trying to use the SYMGET function to retrieve a macro variable, are you?  If so, you don't neet it.  If var5 is already a macro variable then you need to use this syntax:
  %let var1=&var5;

The macro processor resolves &var5 and assigns the text value to var1.  The symget function is used in a DATA step and resolves at execution time, not compile time, so it's very handy.

If you work with macros, you really should get Art Carpenter's book "Carpenters Complete Guide to the SAS Macro Language."  All SAS professionals should have a copy, I think..
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 11

Assisted Solution

by:theartfuldazzler
theartfuldazzler earned 250 total points
ID: 33472833
Hi

Try the CALL SYMPUT function.

DATA _NULL_;
   set Data1;
      CALL SYMPUT('Var1',Var5);
RUN;

%PUT *** &Var1 ***;

This takes the value of Var5 in the dataset Data1 (from the last record) and assigns it to the macro variable Var1
     
0
 

Author Comment

by:labradorchik
ID: 33473916
Thanks guys, but none of the above code is currently working for me...
I tried   %let var1=&var5; instead of %let var1=%SYSGET (var5);

than I tried
DATA _NULL_;
   set Data1;
      CALL SYMPUT('Var1',Var5);
RUN;

%PUT *** &Var1 ***;

In both cases I am getting the following message: WARNING: Apparent symbolic reference VAR5 not resolved.
I thought I referenced "var5" in my data step's PUT statement?!? Am I doing it incorrectly?

I can see my output file "file_.DAT" now, but this file should appear in my directory as "file_50.DAT".
Note: if "var5"=50 for example
0
 

Author Closing Comment

by:labradorchik
ID: 33474169
I am sorry, below code is actually working fine, - I can see now file with the "var5" value embedded in it.
Thanks!!!

DATA _NULL_;
   set Data1;
      CALL SYMPUT('Var1',Var5);
RUN;

Also,
"dirname:file_&var1..DAT";   is the correct format!
Thanks!
0
 

Author Comment

by:labradorchik
ID: 33479001
Only one thing is not working:

My output file "file_&var1.DAT" only contains the last record' value from "var1", - all other values are missed or not recorded.

Here is what I am trying to get:
For every different value of "var1" in the "data" SAS Dataset I am trying to output file "file_&var1.DAT.
So, if SAS dataset "data1" has total of 5 records and values for "var1" are for example 09, 09, 67, 78, 98, than I should have total of 4 "file_&var1.DAT" files as my output:
file_09.DAT
file_67.DAT
file_78.DAT
file_98.DAT

Right now for my output file I am only getting  file_98.DAT, which is my last record' value, which in this case is 98.
How come all other values for "var1" are not recorded and output files are not made?
Thanks!
0
 
LVL 9

Expert Comment

by:bradanelson
ID: 33479050
You will have to create a loop to process the mulitple output datasets needed.  1st, you read the file in to find out how many variations there are of var5 and then loop through a process to create a new dataset for each distinct variation.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question