BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

proc sql;

create table test as

select ln,monthyr

from test99;

quit;

sample output

ln      monthyr

11      201502

12      201503

13      201504

I performed a macro to segment each dataset into its own dataset

%macro (monthyr);

proc sql;

create table test11_&monthyr as

select *

from test;

quit;

%mend;

The objective is to create something like this

test11_201502

test11_201503  etc

The code runs however no segmenting occurs.  What is the issue with my code.  I am somewhat new to macro building.  Note MonthYr is a date data type


2 REPLIES 2
Astounding
PROC Star

Macros are not the answer here.  You need to be able to write a successful program without using macros first.  Once you have that part working correctly, writing the macro will be easy.

Good luck.

dcruik
Lapis Lazuli | Level 10

Are you looking to filter each of your data sets (test11_201502, test11_201503, etc..) only by the monthyr variable?  Otherwise I would agree, a macro is not what you're looking for.  You could loop through each individual monthyr variable one at a time to create the data set names you want, but with the code provided, you will just have the same data in each data set.

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
  • 2 replies
  • 867 views
  • 0 likes
  • 3 in conversation