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;
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;
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;
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.