I have transpose program below. However, I got an error message for Log shown below. Please advice how to fix this question.
proc transpose data=have out=trans
ERROR: Sale1_record does not have a numeric suffix.
To add on to Collin,
You will have to list out all the variables in the var statement since they don't end in a number. Alternatively, you can rename the variables to end with a number if you want to use the '-' feature.
Assuming that 'Sale1_recode' was a typo for 'Sale1_record':
*Method 1; proc transpose data=have out=trans var Sale1_record Sale2_record Sale3_record Sale4_record Sale5_record Sale6_record; by CarID; run; quit; *Method 2; proc transpose data=have(rename=(Sale1_record=Sale_record1 Sale2_record=Sale_record2 Sale3_record=Sale_record3 Sale4_record=Sale_record4 Sale5_record=Sale_record5 Sale6_record=Sale_record6)) out=trans prefix=Sale_record; var Sale_record1-Sale_record6; by CarID; run; quit;
If the variables in the dataset are structured such that each set of names are in order (left to right), you can use '--' for each set of variables. This will take all variables in the dataset between and including the ones listed.
proc transpose data=have out=trans var Sale1_record--Sale6_record; by CarID; run; quit;
In the future make sure to name series of variablees with the sequence number at the end of the name.
Personally for a one off analysis I would just run a little program to generate the names and then copy and paste them.
data _null_; do i=1 to 50 ; name = cats('sales',i,'_record'); put name ; end; run;
If you find that you need to reference a number of different lists of variables in this way then you might want to make a little macro to generate the names.
%macro names(n,prefix,suffix); %local i; %do i=1 %to &n ; &prefix.&i.&suffix %end; %mend; ... var %names(50,sales,_record);
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.