DATA Step, Macro, Functions and more

no change in main file

Reply
Occasional Contributor
Posts: 15

no change in main file

Hi I have imported a data file from CSV fromat  which have 28243 rows and 2296 varables using following code:

PROC IMPORT OUT= Ggp1

     DATAFILE="G:\seleg.csv"

     DBMS=csv REPLACe;

                    GETNAMES=YES;

     DATAROW=2;

        guessingrows=32767

        Run;

 

Now I'm running follwong code:

 

data work.Ggp1;

set work.Ggp1;

array _v{*} v:;

if x1 > 1 then

    do i = max(815,x1) to min(dim(_v),xx1);

        _v{i} = 2;

        end;

drop i;

run;

 

the log shows that the program has run successfully and shows no error message. But I check the data file, I don't see any change in the data file, can you tell my how to fix this problem? 

Super User
Posts: 17,907

Re: no change in main file

[ Edited ]

I would recommend changing the second step such that it creates a new data set, not overwriting the imported data set and then checking.

Please post the log, one check is to make sure your loop condition is ever executed.

data work.check_condition1;
set work.Ggp1;
if x1 > 1 then output;
run;

Occasional Contributor
Posts: 15

Re: no change in main file

hi,

thanks a lot. the attachment contains the CSV file, would you pls check that? mainly I intended to recode the variavbles starts from v815 to v1360, depending the values of x1 and xx1.

Occasional Contributor
Posts: 15

Re: no change in main file

I have created new file instead of reqriting, still there is no change.....actually, if we run the code, the output file should contain 2 instead of 1 from colomn no. 941 to 945 in row 36.
Occasional Contributor
Posts: 15

Re: no change in main file

the log:

data sasuser.ggp2;
2472 set sasuser.ggp1;
2473 array _v{*} v:;
2474 if x1 > 1 then
2475 do i = max(815,x1) to min(dim(_v),xx1);
2476 _v{i} = 5;
2477 end;
2478 drop i;
2479 run;

NOTE: There were 474 observations read from the data set SASUSER.GGP1.
NOTE: The data set SASUSER.GGP2 has 474 observations and 671 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.04 seconds


2480 data work.check_condition1;
2481 set sasuser.ggp1;
2482 if x1 > 1 then output;
2483 run;

NOTE: There were 474 observations read from the data set SASUSER.GGP1.
NOTE: The data set WORK.CHECK_CONDITION1 has 37 observations and 671 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.03 seconds

 

Super User
Posts: 17,907

Re: no change in main file

[ Edited ]

I think the other suggestion of the do loop conditions is correct, once your log is examined. 

Your log shows 671 variables.  So I have no idea what X1 is, but assuming it takes a value within the range of 1 to 671 the max condition always evaluates to 815 and then whatever the lower interval is, but that loop will never execute.  Test the condition again with a put statement. 

 

do i = max(815,x1) to min(dim(_v),xx1);

NOTE: The data set SASUSER.GGP2 has 474 observations and 671 variables.

 

Check the log to see if the loop is ever entered. You could also need a BY -1 if you plan to count down, but then I think the variable i won't be a valid index for your array.

 

data sasuser.ggp2;
set sasuser.ggp1;
array _v{*} v:;
if x1 > 1 then
do i = max(815,x1) to min(dim(_v),xx1);
 _v{i} = 5;
put 'In Do Loop';
 end;
 drop i;
run;

 

 

 

 

Occasional Contributor
Posts: 15

Re: no change in main file

thanks a lot, thank you very much for your cooperaion.....

Super User
Posts: 5,093

Re: no change in main file

There's one additional check to make, concerning this range:

 

do i = max(815,x1) to min(dim(_v),xx1);

 

Have you checked that max(815,x1) is actually less than or equal to min(dim(_v),xx1) ??

Occasional Contributor
Posts: 15

Re: no change in main file

yep, x1 is less than or equal to xx1.

Occasional Contributor
Posts: 15

Re: no change in main file

hi, the attachment contains the CSV data file.

Super User
Posts: 17,907

Re: no change in main file

No attachment...perhaps its being virus checked.
Super User
Posts: 5,093

Re: no change in main file

It's not enough to verify that x1 <= xx1.

 

Even when x1 <= xx1, the DO loop may be starting at 815, not at x1.

 

You have to check for the actual conditions that your program uses.  Are there any observations where:

 

max(815,x1) <= min(dim(_v),xx1) 

Occasional Contributor
Posts: 15

Re: no change in main file

I'm really very new, would u please tell me what does max(815,x1) mean practically?

Occasional Contributor
Posts: 15

Re: no change in main file

wha does the hole statement mean?   max(815,x1) <= min(dim(_v),xx1) 

Super User
Posts: 5,093

Re: no change in main file

As Reeza mentioned, max(815, x1) means whichever is larger (815 or x1).

 

Similary, min takes whichever is smaller (but omits missing values).  So min(dim(_v), xx1) means take whichever is smaller, either the number of elements in the array or the value of xx1.

Ask a Question
Discussion stats
  • 15 replies
  • 302 views
  • 0 likes
  • 3 in conversation