BookmarkSubscribeRSS Feed
mahfuz_pops
Calcite | Level 5

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? 

15 REPLIES 15
Reeza
Super User

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;

mahfuz_pops
Calcite | Level 5

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.

mahfuz_pops
Calcite | Level 5
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.
mahfuz_pops
Calcite | Level 5

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

 

Reeza
Super User

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;

 

 

 

 

mahfuz_pops
Calcite | Level 5

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

Astounding
PROC Star

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) ??

mahfuz_pops
Calcite | Level 5

yep, x1 is less than or equal to xx1.

mahfuz_pops
Calcite | Level 5

hi, the attachment contains the CSV data file.

Reeza
Super User
No attachment...perhaps its being virus checked.
Astounding
PROC Star

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) 

mahfuz_pops
Calcite | Level 5

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

mahfuz_pops
Calcite | Level 5

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

Astounding
PROC Star

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.

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!

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