For a visitor to the country, you're ok wearing what you like, there is no strict rule. However, just dress reasonably conservatively and you'll have no problem. You'll find plenty of Marrakech clothing stalls in the souks to pick up anything you need on the go.