BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I can program this fairly well in Stata, so I am guessing that SAS and IML can do the same thing. I don't know enough about the SAS language to try and look up the bits and pieces of this in the documentation.

Here's the code in Stata:

forvalues i=0/4 {
gen fakevar_`i'=.
}

The internal variable i will take on values 0-4, and this will generate 5 variables with missing values: fakevar_0...fakevar_4. Stata will also interpret the `i' as the value within a text string.

How do I do this in SAS? What do you call those internal variables in loops, and how do I get the statements in the loop to use that value of i in the way I want to use it?

Thanks

GT Message was edited by: Turgidson
4 REPLIES 4
Cynthia_sas
SAS Super FREQ
Hi:
If you're talking about DATA step programs then SAS can treat those numbered variables as though they are members of an ARRAY. This paper has a good introduction to how ARRAYS work in SAS:
http://support.sas.com/rnd/papers/sgf07/arrays1780.pdf

Since IML works with matrices, if your real interest is in IML, matrix addressing is different than array addressing. Here's the IML user's guide:
http://support.sas.com/documentation/cdl/en/imlug/59656/PDF/default/imlug.pdf Chapter 4 discusses how to work with IML matrices, including subscripting.

cynthia
deleted_user
Not applicable
I am hacking my way through IML. and all I wanted to do was create a series of variables that were subscripted.

Y_i=i

I'm translating the code out of Stata and Matlab, where this seems to be an easier thing to do.

Thanks

GT
Peter_C
Rhodochrosite | Level 12
in a data step you can define subscripted variables in many ways. For example
length num1-num25 4;
defines 25 short numeric vars.
retain chr1 - chr9 "ab" ;
defines 9 chrN vars all stsrting with value ;ab
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
FWIW, a separate SAS discussion forum exists for the SAS/IML product. For what you have described in your post (to some extent), there are two different SAS programming techniques, each with their own purpose to do_over/iterate - mentioned below:

DATA step language:

DO I=0 TO 4;
* your SAS DATA step code goes here. ;
END;

MACRO language:

%DO I=0 %TO 4;
%* your SAS macro code goes here. ;
%END;


Suggest you start with some basic SAS system reading and go from there - links to SAS support http://support.sas.com/ website documentation and technical / conference paper references below.

Scott Barry
SBBWorks, Inc.

SAS-hosted DOCUMENTATION references:

SAS(R) 9.2 Language Reference: Concepts, DATA Step Processing:
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001281588.htm

Step-by-Step Programming with Base SAS(R) Software - Introduction to DATA Step Processing
http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001302699.htm

SAS Macro Language: Reference
Introduction to the Macro Facility
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002293969.htm

SAS Language Reference by Name, Product, and Category - Macro Statements Syntax Sorted Alphabetically
http://support.sas.com/documentation/cdl/en/allprodslang/62304/HTML/default/syntaxByType-macroStatem...

SAS SQL Procedure User's Guide - Introduction to the SQL Procedure
http://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/a002536894.htm


CONFERENCE PAPER references:

A Hands-On Introduction to SAS® DATA Step Programming
Debbie Buck, D. B. & P. Associates, Houston, TX (a SUGI conference paper)
http://www2.sas.com/proceedings/sugi30/134-30.pdf

Understanding the SAS® DATA Step and the Program Data Vector
Steven First, Systems Seminar Consultants, Madison, WI
http://support.sas.com/resources/papers/proceedings09/136-2009.pdf

SAS Macro Programming for Beginners
Susan J. Slaughter, Avocet Solutions, Davis, CA
Lora D. Delwiche, Delwiche Consulting, Winters, CA
http://www2.sas.com/proceedings/sugi29/243-29.pdf

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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