[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Initialize variables

Posted on 2011-05-03
3
Medium Priority
?
850 Views
Last Modified: 2013-11-16
Hi,

I have a SAS-dataset with 53 variables. When a certain variable is different from zero then i want to set 39 variables (variable 4 to 42) to zero. I can set them one by one to zero, but is there another way?

Tx
sonmic
0
Comment
Question by:sonmic
  • 2
3 Comments
 
LVL 11

Expert Comment

by:theartfuldazzler
ID: 35511900
Hi

The best way (I think) is to use an ARRAY statement.

The issue is how to list the variable names in the ARRAY statement.  If the variables follow a certain numbering format (say VAR1  VAR2  VAR3 ... VAR53) then the statement can be as follows:

ARRAY ArrName (*) VAR1 - VAR53;

If the variable's are in  the correct order in the dataset, then you can use the following code to get a list of variable names into the macro variable &var_names:

proc sql noprint;
  select name into : var_names separated by ' '
   from dictionary.columns where libname = 'WORK' and memname = 'TEST';
%put &var_names;

Note that WORK and TEST must be in CAPITALS.  (TEST is the name of the dataset)


To answer your query, try the following full code:


 
proc sql noprint;
  select name into : var_names separated by ' '
   from dictionary.columns where libname = 'WORK' and memname = 'TEST';

%put &var_names;

DATA Test;
  set test;
    array ArrName (*) &var_names;

IF Certain_variable ~= 0 then do i = 4 to 53;
   ArrName[i] = 0;
end;
RUN;

Open in new window

0
 

Author Comment

by:sonmic
ID: 35512329
Hi,

Tx for your answer but i get the message :
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
0
 
LVL 11

Accepted Solution

by:
theartfuldazzler earned 1400 total points
ID: 35512354
Hi

Change the Proc sql part to:

proc sql noprint;
  select name into : var_names separated by ' '
   from dictionary.columns where libname = 'WORK' and memname = 'TEST' and type = 'num';
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

873 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