DATA Step, Macro, Functions and more

SAS Array statement assistance

Reply
Contributor
Posts: 60

SAS Array statement assistance

Hello,

 

I have the below code which runs and partially works with one exception - none of the date fields are pulling through? Any reason why this would be?

 

Date fields not pulling through = Last_Deposit and Start_Date

 

DATA DEPOSIT_DATA;
ARRAY RESORT									{3} $500.;			ARRAY UNIT											{3} $500.;	
ARRAY INTERVAL_NO					{3} $500.;			ARRAY BEDS											{3} $500.;	
ARRAY MAX_OCCUPANCY		   {3} $500.;		  ARRAY PRIV_OCCUPANCY		 {3} $500.;
ARRAY OWN_KEY							  {3} $500.; 		 ARRAY RESORTNAME					{3} $500.;
ARRAY RESORTCOUNTRY			  {3} $500.; 		 ARRAY XCH_REL_NO					{3} $500.;
ARRAY START_DATE						{3} $500.;		  ARRAY LAST_DEPOSIT					{3} $500.;
FLAG=0;
DO UNTIL (LAST.SBR_ID);
SET DEPOSITS_TOP3;
BY SBR_ID;
FLAG + 1;
IF FLAG <= 3 THEN DO; RESORT{FLAG}											= RESORT_ID;				END;
IF FLAG <= 3 THEN DO; RESORTNAME{FLAG}							= RESORT_NAME;		END;
IF FLAG <= 3 THEN DO; RESORTCOUNTRY{FLAG}				  = COUNTRY;					END; 
IF FLAG <= 3 THEN DO; UNIT{FLAG}												= UNIT_NO;					END;
IF FLAG <= 3 THEN DO; INTERVAL_NO{FLAG}							 = INTERVAL;				END;
IF FLAG <= 3 THEN DO; BEDS{FLAG}												 = BED;								END;
IF FLAG <= 3 THEN DO; MAX_OCCUPANCY{FLAG}				= MAX_OCC;				END;	
IF FLAG <= 3 THEN DO; PRIV_OCCUPANCY{FLAG}				  = PRIV_OCC;				END;
IF FLAG <= 3 THEN DO; OWN_KEY{FLAG}									   = OWNERSHIP_KEY;	END;
IF FLAG <= 3 THEN DO; XCH_REL_NO{FLAG}							  = XCH_SPB_REL_NO;	END;
IF FLAG <= 3 THEN DO; START_DATE{FLAG}							  = START_DT;	END;
IF FLAG <= 3 THEN DO; LAST_DEPOSIT{FLAG}							  = LAST_DEPOSIT_DT;	END;
END;
DROP 	FLAG RESORT_ID UNIT_NO INTERVAL BED MAX_OCC PRIV_OCC OWNERSHIP_KEY RESORT_NAME COUNTRY XCH_SPB_REL_NO KEY START_DT LAST_DEPOSIT_DT SPB_TYPE ;
RUN;

 

Cheers,

Cameron

Super User
Super User
Posts: 7,955

Re: SAS Array statement assistance

Posted in reply to CamRutherford

Can I ask that you provide test data - in the form of a datastep - and what the output should look like.  Your code (while being hard to read) seems to be over complicated, and without the data its next to impossible to even see what is going on let alone answer the question.  At a guess your trying to transpose some data, a simpler approach is to set variable name in the dataset, then use the actual transpose procedure, far simpler.  If you provide test data (form of datastep) then can show some code.

Respected Advisor
Posts: 3,799

Re: SAS Array statement assistance

Posted in reply to CamRutherford

What is the data type for START_DT and the other date variable?  Do you see message about conversion of numeric to character?

Contributor
Posts: 60

Re: SAS Array statement assistance

Posted in reply to data_null__

Both in DATE9 format

Trusted Advisor
Posts: 1,566

Re: SAS Array statement assistance

Posted in reply to CamRutherford

Excuse me but your code seems clumsy.

I have just copied your code and made aesthetic changes:

DATA DEPOSIT_DATA;
ARRAY RESORT			{3} $500.;			
ARRAY UNIT			{3} $500.;	
ARRAY INTERVAL_NO		{3} $500.;			
ARRAY BEDS			{3} $500.;	
ARRAY MAX_OCCUPANCY		{3} $500.;		  
ARRAY PRIV_OCCUPANCY    	{3} $500.;
ARRAY OWN_KEY			{3} $500.; 		 
ARRAY RESORTNAME		{3} $500.;
ARRAY RESORTCOUNTRY		{3} $500.; 		 
ARRAY XCH_REL_NO		{3} $500.;
ARRAY START_DATE		{3} $500.;		  
ARRAY LAST_DEPOSIT		{3} $500.;
FLAG=0;

DO UNTIL (LAST.SBR_ID);
 SET DEPOSITS_TOP3;
  BY SBR_ID;
	FLAG + 1;
	IF FLAG <= 3 THEN DO; 
	   RESORT{FLAG}		= RESORT_ID;		 
	   RESORTNAME{FLAG}	= RESORT_NAME;		 
	   RESORTCOUNTRY{FLAG}	= COUNTRY;			   
	   UNIT{FLAG}		= UNIT_NO;			
	   BEDS{FLAG}		= BED;				
	   MAX_OCCUPANCY{FLAG}	= MAX_OCC;				
	   PRIV_OCCUPANCY{FLAG} = PRIV_OCC;			
	   OWN_KEY{FLAG}	= OWNERSHIP_KEY;	
	   XCH_REL_NO{FLAG}	= XCH_SPB_REL_NO;	
           START_DATE{FLAG}	= START_DT;			
	   LAST_DEPOSIT{FLAG}	= LAST_DEPOSIT_DT;	
	END;
END;
DROP 	FLAG RESORT_ID UNIT_NO INTERVAL BED MAX_OCC PRIV_OCC OWNERSHIP_KEY 
        RESORT_NAME COUNTRY XCH_SPB_REL_NO KEY START_DT LAST_DEPOSIT_DT SPB_TYPE ;
RUN;

It seems that there are just two date variables:  START_DT and LAST_DEPOSIT_DT.

Are those sas date variables ? if yes then those are numeric while the appropriate arrays were defined with $ as character.

 

What is the reason you defined all arrays as $500 ? Are your variables so long ? 

Super User
Posts: 11,343

Re: SAS Array statement assistance

Posted in reply to CamRutherford

When you say 'not pulling through' do you mean that you have missing or blank values for the Start_date and Last_deposit or do you see numeric values like 20725? If you see something like 20725 it means that the value was converted from the numeric SAS date value to digits, defaulting to best. format because you did not provide any rule for the numeric to character.

You might want

START_DATE{FLAG} = put(START_DT,date9.); if you actually want a character value for date.

OR have the date arrays as numeric and assign a proper date format.

 

Ask a Question
Discussion stats
  • 5 replies
  • 162 views
  • 1 like
  • 5 in conversation