BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mariange8282
Obsidian | Level 7

Hi, I'm trying to create a counting variable in PROC SQL to give name to tables. 

 

PROC SQL;

i=1;

CREATE TABLE i AS SELECT* FROM A.A WHERE XX=i;

RUN;

 

I can not declarete the variable i to make it interactive. 

 

1 ACCEPTED SOLUTION
4 REPLIES 4
Reeza
Super User

The usual recommendation is don't do this...if you specify why, send can usually offer a more efficient alternative. 

 

Otherwise You want a macro loop. 

 

http://www.ats.ucla.edu/stat/sas/seminars/sas_macros_introduction/

https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Ap...

 

How to split a table by groups. 

http://blogs.sas.com/content/sasdummy/2015/01/26/how-to-split-one-data-set-into-many/

 

Tom
Super User Tom
Super User

You need to use macro language to generate code.

%let id=100 ;
%let inds=a.a ;


proc sql ;
   create table x&id as 
     select * 
     from &inds
     where id = &id
   ;
quit;
mariange8282
Obsidian | Level 7

Thanks, it was just the sintaxsis.. but I just forget said I want a loop. I change my code for this:

 

%LET i=1;

 

DATA A.A_&i;

SET A.A(WHERE=(XX=&i));

RUN;

 

But I need, i=i+1 

 

%LET i=1;

DATA A.A_&i;
SET A.A(WHERE=(XX=&i));

i=i+1
RUN;

 

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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