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

Hello

I am creating a data set .

Why the order of columns is : transfer_description,ID,amount 

and not: ID ,transfer_description,amount?

How can I change the order without using Retain?

data have;
infile datalines delimiter='|';
informat transfer_description $200.;
input ID  transfer_description  amount;
datalines;
111|Transfer to my friend Joe Kaplan|1000 
111|Salary IBM|2000
111|Salary WIZZ|3980
111|Transfer to my father|500
333|Transfer to my gf|4000
333|Son help|3000
222|Salary IBM|1500
222|Charity|2500
222|Charity|3000
222|transfer to my friend Jula|8000
;
Run;
1 ACCEPTED SOLUTION

Accepted Solutions
japelin
Rhodochrosite | Level 12

Since the variable "transfer_description" is created first in the informat statement line, the order of the variables becomes transfer_description,ID,amount.

To prevent this from happening, use the length statement first to define the variables.

 

data have;
length id 8 transfer_description $200 amount 8;/* add this statement. */
infile datalines delimiter='|';
informat transfer_description $200.;
input ID  transfer_description  amount;
datalines;
111|Transfer to my friend Joe Kaplan|1000 
111|Salary IBM|2000
111|Salary WIZZ|3980
111|Transfer to my father|500
333|Transfer to my gf|4000
333|Son help|3000
222|Salary IBM|1500
222|Charity|2500
222|Charity|3000
222|transfer to my friend Jula|8000
;
Run;

View solution in original post

2 REPLIES 2
japelin
Rhodochrosite | Level 12

Since the variable "transfer_description" is created first in the informat statement line, the order of the variables becomes transfer_description,ID,amount.

To prevent this from happening, use the length statement first to define the variables.

 

data have;
length id 8 transfer_description $200 amount 8;/* add this statement. */
infile datalines delimiter='|';
informat transfer_description $200.;
input ID  transfer_description  amount;
datalines;
111|Transfer to my friend Joe Kaplan|1000 
111|Salary IBM|2000
111|Salary WIZZ|3980
111|Transfer to my father|500
333|Transfer to my gf|4000
333|Son help|3000
222|Salary IBM|1500
222|Charity|2500
222|Charity|3000
222|transfer to my friend Jula|8000
;
Run;
Kurt_Bremser
Super User

The order of variables in the PDV is determined by the order in which the variables are encountered by the data step compiler, so transfer_description is first.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1061 views
  • 1 like
  • 3 in conversation