BookmarkSubscribeRSS Feed
woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

Hi friends -  please help.


I have one same SAS dataset (dataset name: test) getting generated in 10 directories. In "test" dataset i have one variable (date) which has value as "Wed, Feb 18, 2015", (same value on all 10 "test" dataset). i wants to check if any test dataset doesn't has value as today's date format. For instance if i am running code today i wants to see which "test" dataset has different value than "Wed, Feb 18, 2015" and wants to create datasets with list of directory and then will export same to me.  (lets say if i don't have "Wed, Feb 18, 2015" value for "test" dataset under "dir1" and "dir9" then one dataset, for example "output_test" should be generated which has one variable (name any) with value "dir1" and "dir9"



d:\woo\dir1\test ("test" is SAS dataset)

d:\woo\dir2\test

d:\woo\dir3\test

.

.

.

d:\woo\dir10\test


I am thinking like this but not sure.

%macro mycheck;

libname fin&i. "d:\woo\dir&i.";

%do i=1 %to 10;

data woo;

set fin&i..test;

format date weekdate17.;

%if date ne &sysdate. %then

    %do;

        /*create dataset which shows which test dataset under specific directory not having today's date*/

  %end;

%end;

%mend;

%mycheck;

6 REPLIES 6
TomKari
Onyx | Level 15

Hi, Woo

It's not bad; the concept is sound, and it generally looks okay. There's about a million ways to do this, but yours should work. A couple of comments:

Your libname statement needs to be inside your %do loop.

No need to make the library names different in each iteration; the only variable element is the directory name, which you've taken care of.

I'm not setting up an environment to run your code, but I believe it will be running properly fairly quickly.

Tom

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

can someone plz help with logic?

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

below logic is giving me everything (all 10 sas dataset name with dif&i. + 10 datasets with woo&i. - instead it supposed to give only two dataset where date variable is not equal to today in my case)

%macro mycheck;

%do i=1 %to 10;

libname fin&i. "d:\woo\dir&i.";

data woo&i.  dif&i.;

set fin&i..test;

%if date ne &sysdate. %then

    %do;

        output dif&i.;

  %end;


%end;

%mend;

%mycheck;

TomKari
Onyx | Level 15

Hi, Woo

First, change

%if date ne &sysdate. %then

    %do;

        output dif&i.;

  %end;

to

if date ne &sysdate. then

    do;

        output dif&i.;

  end;

The first version is using the macro processor, which you don't want to do. Your dataset references are a little confused, they may need some work.

Keep working through it...you're close.

Tom

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

actually it's not helping - i am using below code and getting error: ALSO - JUST TO MAKE SURE I HAVE DATE value = Fri, Feb 20, 2015

%macro mycheck;

%do i=1 %to 10;

libname fin&i. "d:\woo\dir&i.";

data woo&i.  dif&i.;

set fin&i..test;


if date ne &sysdate. then

    do;

        output dif&i.;

  end;


%end;

%mend;

%mycheck;

_____________________________

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>,

              =, >, ><, >=, AND, EQ, GE, GT, LE, LT, MAX, MIN, NE, NG, NL, OR, ^=, |, ||, ~=.

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

either this logic is not working

%macro mycheck;

%do i=1 %to 10;

libname fin&i. "d:\woo\dir&i.";

data woo&i. ;

set fin&i..test;

    call symput ("fdate", put("&sysdate"d, weekdate17.));

    if date ne &fdate. then

         do;

              output woo&i.;

         end;

run;


%end;

%mend;

%mycheck;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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