BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mehong19
Obsidian | Level 7

Not quite sure what the wrong place is in my array declaration. Log messege is after the code. I created two character arrays and want to pass old variables to newly-defined variables.

 

Many thanks for help

 

Code:

 

DATA SOURCE2;
 SET RAW.SOURCE2;
 INPUT PE $ FR $ EE $ AD $ VAR1-VAR10 $;
 ARRAY NEWVAR[*] $ PUBDATE FRCTQTR ESTTYPE ANALID VAR1-VAR10;
 ARRAY OLDVAR[*] $ A B C D E F G H I J K L M N;
 
 DO X = 1 TO DIM(NEWVAR);
  NEWVAR[X] = OLDVAR[X];
 END;
 DROP A B C D E F G H I J K L M N;
RUN;

 

Log messege

 

1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

55
56 DATA SOURCE2;
57 SET RAW.SOURCE2;
58 INPUT PUBDATE $ FRCTQTR $ ESTTYPE $ ANALID $ VAR1-VAR10 $;
59 ARRAY NEWVAR[*] $ PUBDATE FRCTQTR ESTTYPE ANALID VAR1-VAR10;
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
60 ARRAY OLDVAR[*] $ A B C D E F G H I J K L M N;
61
62 DO X = 1 TO DIM(NEWVAR);
63 NEWVAR[X] = OLDVAR[X];
64 END;
65 DROP A B C D E F G H I J K L M N;
66 RUN;
 
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.SOURCE2 may be incomplete. When this step was stopped there were 0 observations and 15 variables.
WARNING: Data set WORK.SOURCE2 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.04 seconds
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You've got a few things going on there.

 

I'm not sure why you have a SET and INPUT? Input is made to read data in, I don't think you're doing that. Remove that line entirely. 

 

Check the variable types of the old variable from RAW.SOURCE2 -> PROC CONTENTS. Check that all the variables are character already.

 

It also looks like you might be mixing up your old/new variables but I can't even be sure right now.

 

 

 

 

 

View solution in original post

3 REPLIES 3
Reeza
Super User

You've got a few things going on there.

 

I'm not sure why you have a SET and INPUT? Input is made to read data in, I don't think you're doing that. Remove that line entirely. 

 

Check the variable types of the old variable from RAW.SOURCE2 -> PROC CONTENTS. Check that all the variables are character already.

 

It also looks like you might be mixing up your old/new variables but I can't even be sure right now.

 

 

 

 

 

mehong19
Obsidian | Level 7

Variables A to N are old variables. I like to replace with a set of appropriate new variables by using array. I checked, all the variables, A to N, are character already.

 

Just a qucik clarification needed. About INPUT statement, would you mean, in general case, it will be used for read data in such as using DATALINE for data creation?

 

Alphabetic List of Variables and Attributes # Variable Type Len Format Informat Label 1 2 3 4 5 6 7 8 9 10 11 12 13 14

AChar16$16.$16.A
BChar16$16.$16.B
CChar12$12.$12.C
DChar16$16.$16.D
EChar10$10.$10.E
FChar10$10.$10.F
GChar15$15.$15.G
HChar15$15.$15.H
IChar14$14.$14.I
JChar15$15.$15.J
KChar15$15.$15.K
LChar16$16.$16.L
MChar16$16.$16.M
NChar15$15.$15.N
mehong19
Obsidian | Level 7

Hi! I started over my University Edition and removed the INPUT statement as you said. The program works now. Thanks!!

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