Hi all,
I wasn't clear on my previous question and had assumed proc transpose was the way to go .
I will delete that post and re-post below .
I haven't posted the whole data , but my columns in the have are about 500 columns .
Similarly about 500 rows.
Please find atttached a Sample-Dimension1.csv with the data that needs to be flipped .
Please let me know if I need to provide further information.
Have
| FI | 101 Capital Region R Uwgt | 101 Capital Region R 000s |
| Health Products Use Vitamins tablets capsules | 66 | 64 |
| Health Products Use Anti smoking products | 5 | 5 |
| Anti smoking prdcts Freq Buy Every 2 to 3 months | 0 | 0 |
| Anti smoking prdcts Freq Buy Every 4 to 6 months | 0 | 0 |
| Weight Loss Remedies Freq Buy Every 2 to 3 months | 3 | 5 |
| Weight Loss Remedies Freq Buy Every 4 to 6 months | 0 | 0 |
Want
| F1 | Health Products Use Vitamins tablets capsules | Health Products Use Anti smoking products | Anti smoking prdcts Freq Buy Every 4 to 6 months | Weight Loss Remedies Freq Buy Every 2 to 3 months | Weight Loss Remedies Freq Buy Every 4 to 6 months |
| 101 Capital Region R Uwgt | 66 | 5 | 0 | 3 | 0 |
| 101 Capital Region R 000s | 64 | 5 | 0 | 5 | 0 |
Please provide better HAVE data in the form of a data step with cards data.
data have;
infile cards expandtabs;
input FI&$64. a b;
id + 1;
label a='101 Capital Region R Uwgt' b='101 Capital Region R 000s';
cards;
Health Products Use Vitamins tablets capsules 66 64
Health Products Use Anti smoking products 5 5
Anti smoking prdcts Freq Buy Every 2 to 3 months 0 0
Anti smoking prdcts Freq Buy Every 4 to 6 months 0 0
Weight Loss Remedies Freq Buy Every 2 to 3 months 3 5
Weight Loss Remedies Freq Buy Every 4 to 6 months 0 0
;;;;
proc print;
run;
proc transpose data=have out=want(drop=_name_) prefix=FI label=F1;
var a b;
id id;
idlabel fi;
run;
proc contents varnum;
proc print;
run;
proc print label;
label f1=' ';
run;
First, transpose your 500 columns to a long format BY fi.
Then, run a PROC REPORT with fi as an ACROSS column.
For code suggestions, provide your dataset in a data step with datalines that works and creates a dataset with valid SAS names.
Please provide better HAVE data in the form of a data step with cards data.
data have;
infile cards expandtabs;
input FI&$64. a b;
id + 1;
label a='101 Capital Region R Uwgt' b='101 Capital Region R 000s';
cards;
Health Products Use Vitamins tablets capsules 66 64
Health Products Use Anti smoking products 5 5
Anti smoking prdcts Freq Buy Every 2 to 3 months 0 0
Anti smoking prdcts Freq Buy Every 4 to 6 months 0 0
Weight Loss Remedies Freq Buy Every 2 to 3 months 3 5
Weight Loss Remedies Freq Buy Every 4 to 6 months 0 0
;;;;
proc print;
run;
proc transpose data=have out=want(drop=_name_) prefix=FI label=F1;
var a b;
id id;
idlabel fi;
run;
proc contents varnum;
proc print;
run;
proc print label;
label f1=' ';
run;
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 save with the early bird rate—just $795!
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.